CloudWatch: metrics, alarms and logs
CloudWatch is the default monitoring backbone for AWS. Every service pushes metrics automatically at 5-minute intervals (standard resolution). Enable Detailed Monitoring on EC2 to get 1-minute granularity - this costs extra and is NOT on by default.
Custom metrics are published with PutMetricData. You can go below 1 minute using High-Resolution metrics (down to 1 second), but this needs the StorageResolution parameter set to 1.
Metric retention matters for the exam
- Data at 1-second resolution is kept for 3 hours
- 1-minute data points are kept for 15 days
- 5-minute data points are kept for 63 days
- 1-hour data points are kept for 15 months
CloudWatch automatically 'rolls up' older data to coarser resolution - it does not delete it early.
Alarms
An alarm watches a single metric (or a metric math expression) over a number of evaluation periods and moves between OK, ALARM and INSUFFICIENT_DATA states. Composite alarms combine multiple alarms with AND/OR logic. Alarms can trigger SNS notifications, Auto Scaling actions, or EC2 actions (stop, terminate, reboot, recover).
Logs
CloudWatch Logs organises data into Log Groups then Log Streams. Set retention per log group (default is Never Expire, which quietly costs money forever - a classic gotcha). Use Metric Filters to turn log patterns (like ERROR strings) into numeric CloudWatch metrics you can alarm on. Subscription Filters stream logs in near real time to Lambda, Kinesis or OpenSearch for further processing. CloudWatch Logs Insights lets you query log data with its own query language without building a pipeline first.
CloudWatch Events / EventBridge
EventBridge (the evolution of CloudWatch Events) reacts to AWS service state changes or scheduled rules (cron/rate expressions) and routes them to targets like Lambda or SNS.
X-Ray for distributed tracing
X-Ray traces a request as it moves through microservices, showing a service map and latency breakdown per hop (called segments and subsegments). You must install the X-Ray daemon (or use the built-in agent on Lambda) and instrument your code with the X-Ray SDK. Annotations are indexed key-value pairs you can filter traces by; metadata is not indexed and is for extra context only. Sampling defaults to recording the first request each second plus 5% of additional requests - tune this with sampling rules to control cost.
Common exam traps
- Detailed Monitoring (1-min) is opt-in and chargeable, not default
- Metric filters count matching log LINES, they don't parse arbitrary JSON structure without a defined pattern
- X-Ray needs IAM permissions (xray:PutTraceSegments) even inside Lambda
- Annotations are searchable, metadata is not - mixing these up is a favourite distractor
What is the default CloudWatch metric resolution for most AWS services?
5 minutes (standard resolution); Detailed Monitoring gives 1-minute but must be enabled and costs extra
tap to reveal
How do you publish a custom metric at sub-minute resolution?
Call PutMetricData with StorageResolution set to 1, giving 1-second high-resolution metrics
tap to reveal
How long is 1-minute resolution CloudWatch metric data retained?
15 days
tap to reveal
How long is 5-minute resolution CloudWatch metric data retained?
63 days
tap to reveal
How long is 1-hour resolution CloudWatch metric data retained?
15 months
tap to reveal
What is the default log group retention period in CloudWatch Logs?
Never Expire - you must set a retention policy explicitly or logs (and cost) accumulate forever
tap to reveal
What turns a CloudWatch Logs pattern into an alarmable numeric metric?
A Metric Filter
tap to reveal
What streams CloudWatch Logs data to Lambda, Kinesis or OpenSearch in near real time?
A Subscription Filter
tap to reveal
What combines multiple CloudWatch alarms with AND/OR logic?
A Composite Alarm
tap to reveal
What are the three states a CloudWatch alarm can be in?
OK, ALARM, and INSUFFICIENT_DATA
tap to reveal
What component collects trace data on an EC2 instance for X-Ray?
The X-Ray daemon (on Lambda, tracing is built in without needing a separate daemon)
tap to reveal
What is X-Ray's default sampling behaviour?
Records the first request each second plus 5% of any additional requests, and this is configurable via sampling rules
tap to reveal
What is the difference between X-Ray Annotations and Metadata?
Annotations are indexed key-value pairs you can search/filter traces by; Metadata is not indexed and is for extra context only
tap to reveal
What IAM permission does X-Ray tracing require to send trace data?
xray:PutTraceSegments
tap to reveal
What service replaced and expanded CloudWatch Events for event-driven routing?
Amazon EventBridge, which routes AWS state changes or scheduled cron/rate rules to targets like Lambda or SNS
tap to reveal