CloudWatch alarms
CloudWatch alarm states and periods, alarm targets, composite alarms, EC2 instance recovery, alarms on log metric filters, testing alarms, and CloudWatch Network Synthetic Monitor.
Alarms
CloudWatch alarms trigger notifications or actions for any metric.
- Various options: sampling, percentage, maximum, minimum…
- Alarm states:
- OK;
- INSUFFICIENT_DATA;
- ALARM.
- Period: the length of time, in seconds, over which the metric is evaluated. High-resolution custom metrics allow periods of 10 or 30 seconds, or multiples of 60.
Alarm targets
- EC2 actions: stop, terminate, reboot or recover an EC2 instance.
- Trigger an Auto Scaling action.
- Send a notification to SNS (from which pretty much anything is possible).
Updated since the slides
Alarms can now also invoke a Lambda function directly (no SNS topic in between) and create Systems Manager OpsItems or incidents.
Composite alarms
- A normal CloudWatch alarm watches a single metric.
- Composite alarms monitor the states of multiple other alarms.
- AND and OR conditions (and NOT).
- Helpful to reduce "alarm noise": for example, high CPU alone is normal during a batch job, but high CPU and high IOPS means trouble.
EC2 instance recovery
Status checks:
- Instance status: checks the EC2 virtual machine (software, network config of the instance).
- System status: checks the underlying hardware (AWS's host).
- Attached EBS status: checks the attached EBS volumes.
Recovery: an alarm on StatusCheckFailed_System with the recover action moves the instance to new hardware and keeps the same private and public IPv4 addresses, Elastic IP, metadata and placement group.
Supported instance types now also have simplified automatic recovery, turned on by default, which does the same without an alarm.
Good to know
-
Alarms can be created on CloudWatch Logs metric filters: a metric filter turns matching log lines into a metric.
-
To test alarms and notifications, set the alarm state to ALARM with the CLI:
aws cloudwatch set-alarm-state --alarm-name "myalarm" \ --state-value ALARM --state-reason "testing purposes"
CloudWatch Network Synthetic Monitor
- Monitors and detects network issues between apps hosted on AWS and an on-premises data center.
- Identifies network performance degradation (packet loss, latency, jitter…).
- No agents to install.
- Tests ICMP or TCP traffic to IPv4 or IPv6 on-premises destinations through Direct Connect or Site-to-Site VPN connections.
- Publishes data to CloudWatch metrics.
Real-world examples
- A web team alarms when the ALB's 5xx error count is above 50 for 3 minutes, and SNS pages the on-call engineer.
- A trading firm uses Network Synthetic Monitor to alert when packet loss on its Direct Connect link rises above 1%.
Exam tips
- "Automatically recover an EC2 instance on hardware failure, keeping its IP" → alarm on
StatusCheckFailed_Systemwith the recover action (or simplified automatic recovery). - "Reduce alarm noise", "alert only when several conditions are true" → composite alarm.
- "Alarm on errors in logs" → metric filter + alarm.
- "Test an alarm's notification" →
set-alarm-state. - "Monitor latency and packet loss to on premises over Direct Connect or VPN, no agents" → Network Synthetic Monitor.
Common traps
- "Recover changes the instance's IP." Recovery keeps the IPs; a stop and start changes the public IP (unless it's an Elastic IP).
- "An alarm can watch several metrics at once." One metric (or metric math); combine alarms with a composite alarm.
Hands-on lab: an alarm with an email
Goal: create an alarm, send its notification to your email, and test it.
Costs money
A standard alarm costs about $0.10 a month, charged by the hour, and SNS emails are about $2 per 100,000, so this lab costs less than a cent. Any Region works.
Create the alarm
Use the MyApp / ActiveUsers metric from the metrics lab (or any metric). CloudWatch → Alarms → Create alarm, select the metric, condition Greater than 1000.
Add the notification
Create a new SNS topic saa-alarms with your email address. Name the alarm saa-test-alarm and create it. Confirm the subscription email.
Test it
In CloudShell, run set-alarm-state with --alarm-name saa-test-alarm.
Expected result: the alarm turns red for a moment and you receive an "ALARM" email.
Clean up: delete the alarm and the saa-alarms topic.
AWS documentation
CloudWatch Logs
CloudWatch Logs groups and streams, retention, encryption and log classes, log sources, Logs Insights, exporting to S3, subscriptions, cross-account aggregation, and the CloudWatch agent.
CloudWatch Insights
CloudWatch Container Insights, Lambda Insights, Contributor Insights and Application Insights, and which one answers which monitoring question.