Skip to Content
Asterrr's Handbook
2 · Incident response

CloudWatch Logs and Agent

Log groups, retention, the unified CloudWatch agent, agent troubleshooting and CloudWatch IAM managed policies.

The decision: where do logs live, how long are they kept, and why did an instance or function stop shipping them?

CloudWatch is the main monitoring service. Metrics, alarms and dashboards watch resources. CloudWatch Logs stores and searches log events. EventBridge routes change events to targets. Dashboards are global, not tied to one Region.

VPCpermissionsPutLogEventsquerystreamEC2 with agentInstance rolecredsLog group andstreamLogs InsightsSubscription toFirehose
The unified agent needs an instance role and a network path to the CloudWatch Logs endpoint. Missing either one is the usual reason logs stop.

Core facts

ItemWhat to remember
Log groupShares retention, monitoring and access control. Holds any number of log streams
Log streamEvents from one source, such as one instance
RetentionDefault is never expire. Per log group you can pick 1 day up to 3,653 days (10 years)
Deletion lagExpired events can take up to 72 hours to actually disappear
Account-level retention policyOverrides group settings, applies by name prefix, minimum 30 days, takes effect after 24 hours
Logs InsightsInteractive queries across one or more log groups
Metric filterTurns matching events into a metric. Details on the next page
Late eventsPutLogEvents rejects events older than 14 days or more than 2 hours in the future
Unified CloudWatch agentCollects logs and system metrics (memory, disk) from EC2 and on-premises servers. Also takes StatsD and collectd custom metrics
Old awslogs agentLogs only. Deprecated and unsupported
DashboardsGlobal. Access through identity-based policies

Legacy

The old awslogs agent (config in /etc/awslogs/, log at /var/log/awslogs.log) appears in older material. The unified CloudWatch agent replaces it.

Agent troubleshooting

Almost every question reduces to three causes.

CauseCheck
MisconfigurationAgent running, config file valid, log paths correct, rotation pattern supported
PermissionsRole needs logs:CreateLogGroup, logs:CreateLogStream, logs:PutLogEvents and logs:DescribeLogStreams. Metrics also need cloudwatch:PutMetricData. A NoCredentialsError means no role is attached. An access denied error means the role lacks the actions
ConnectivityA route to the CloudWatch Logs endpoint through an internet gateway, NAT gateway or an interface VPC endpoint. Check security group, network ACL and route table
  • Lambda writes logs through its execution role. If a function shows no logs, the role lacks CloudWatch Logs permissions.
  • On-premises servers have no instance role. The agent uses an IAM user with programmatic access keys.
  • Supported rotation: rename with a numeric suffix then recreate, or create a new file with the same pattern and a new suffix. Copy-then-truncate can lose events.

IAM managed policies

PolicyAllows
CloudWatchFullAccessEverything in CloudWatch. Admin only, not least privilege
CloudWatchReadOnlyAccessRead operations such as get metrics and list dashboards
CloudWatchActionsEC2AccessRead alarms and metrics, plus the EC2 stop, reboot and terminate actions used by alarm actions

Exam trap

Production users who only need to view graphs get CloudWatchReadOnlyAccess. CloudWatchFullAccess is the distractor.

Further reading

On this page