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.
Core facts
| Item | What to remember |
|---|---|
| Log group | Shares retention, monitoring and access control. Holds any number of log streams |
| Log stream | Events from one source, such as one instance |
| Retention | Default is never expire. Per log group you can pick 1 day up to 3,653 days (10 years) |
| Deletion lag | Expired events can take up to 72 hours to actually disappear |
| Account-level retention policy | Overrides group settings, applies by name prefix, minimum 30 days, takes effect after 24 hours |
| Logs Insights | Interactive queries across one or more log groups |
| Metric filter | Turns matching events into a metric. Details on the next page |
| Late events | PutLogEvents rejects events older than 14 days or more than 2 hours in the future |
| Unified CloudWatch agent | Collects logs and system metrics (memory, disk) from EC2 and on-premises servers. Also takes StatsD and collectd custom metrics |
| Old awslogs agent | Logs only. Deprecated and unsupported |
| Dashboards | Global. 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.
| Cause | Check |
|---|---|
| Misconfiguration | Agent running, config file valid, log paths correct, rotation pattern supported |
| Permissions | Role 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 |
| Connectivity | A 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
| Policy | Allows |
|---|---|
CloudWatchFullAccess | Everything in CloudWatch. Admin only, not least privilege |
CloudWatchReadOnlyAccess | Read operations such as get metrics and list dashboards |
CloudWatchActionsEC2Access | Read 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.