Skip to Content

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

CloudWatch alarm targets: when a metric crosses its threshold the alarm moves between the OK, INSUFFICIENT_DATA and ALARM states and can stop, terminate, reboot or recover an EC2 instance, scale an Auto Scaling group, notify SNS, invoke a Lambda function, or create a Systems Manager OpsItem or incident CloudWatch alarm targets: when a metric crosses its threshold the alarm moves between the OK, INSUFFICIENT_DATA and ALARM states and can stop, terminate, reboot or recover an EC2 instance, scale an Auto Scaling group, notify SNS, invoke a Lambda function, or create a Systems Manager OpsItem or incident

What an alarm can do when it fires.
  • 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 composite alarm: alarm A watches the instance's CPU and alarm B its IOPS; the composite alarm goes into ALARM only when A AND B are both in ALARM, and then sends one alert to SNS A composite alarm: alarm A watches the instance's CPU and alarm B its IOPS; the composite alarm goes into ALARM only when A AND B are both in ALARM, and then sends one alert to SNS

Alert only when several things go wrong together.
  • 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

EC2 instance recovery: a CloudWatch alarm on StatusCheckFailed_System monitors the instance; when the underlying hardware fails it alerts an SNS topic and recovers the instance onto new hardware with the same private and public IP addresses, Elastic IP, metadata and placement group EC2 instance recovery: a CloudWatch alarm on StatusCheckFailed_System monitors the instance; when the underlying hardware fails it alerts an SNS topic and recovers the instance onto new hardware with the same private and public IP addresses, Elastic IP, metadata and placement group

Move the same instance to healthy hardware.

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

An alarm on logs: a metric filter on a log group counts lines containing ERROR and publishes a metric; a CloudWatch alarm on that metric alerts the on-call team through SNS when there are more than 10 a minute An alarm on logs: a metric filter on a log group counts lines containing ERROR and publishes a metric; a CloudWatch alarm on that metric alerts the on-call team through SNS when there are more than 10 a minute

Turn log lines into a metric, then alarm on it.
  • 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_System with 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

On this page

Open notes

Spotted a mistake?

These notes are open source. Suggest a fix, or star the repo if they helped you.

Suggest an edit

For AI agents: llms.txt · llms-full.txt