How do Amazon CloudWatch Alarms work, and how would you set one up to alert on a production issue without causing alert fatigue?
Answer
A CloudWatch Alarm watches a single metric (or a metric math expression) and compares it to a threshold over a time window. It moves between three states, OK, ALARM, and INSUFFICIENT_DATA, and every state change can trigger actions such as notifying an SNS topic, scaling an Auto Scaling group, stopping or recovering an EC2 instance, or invoking a Lambda function. Good alarms use multiple data points and sensible missing-data handling so one noisy spike does not page someone at 3 a.m.
The settings that control when an alarm fires
Metric and statistic: for example CPUUtilization with Average, or TargetResponseTime with p99.
Period: the length of each data point, usually 60 seconds. High-resolution alarms can use 10- or 30-second periods for custom high-resolution metrics.
Threshold and comparison: for example GreaterThanThreshold 80.
Evaluation periods (N) and datapoints to alarm (M): "M out of N". 3 out of 5 one-minute periods means the condition must hold in 3 of the last 5 minutes. This is the main tool against flapping.
Missing data treatment: missing (default), notBreaching, breaching, or ignore. For a metric that only exists when errors happen, notBreaching avoids a constant INSUFFICIENT_DATA state.
What an alarm can do
Action type
Example
SNS notification
Email, SMS, or a Lambda that posts to Slack or PagerDuty
EC2 action
Stop, terminate, reboot, or recover an instance
Auto Scaling
Add instances when CPU stays high (target tracking creates these alarms for you)
Lambda
Invoke a function directly for automated remediation
Systems Manager
Create an OpsItem or incident
Actions are configured per state, so you can also send an "all clear" when the alarm returns to OK.
Smarter alarm types
Composite alarms combine other alarms with AND/OR/NOT logic. Page only when high latency and high error rate are both true, instead of two separate pages.
Anomaly detection alarms learn a metric's normal band, including daily and weekly patterns, and alarm when it leaves the band. Useful when "normal" traffic at 9 p.m. is very different from 4 a.m.
Metric math alarms alarm on derived values like error rate (5XX / RequestCount * 100) instead of raw counts.
Avoiding alert fatigue
Alarm on symptoms users feel (error rate, p99 latency, queue age) rather than every cause (CPU on one host).
Use "M out of N" and composite alarms to suppress short blips.
Route severities differently: critical to on-call, warning to a channel.
Alarm on the DLQ depth and on missing heartbeats for batch jobs, which are easy to forget.
Gotchas
Alarms evaluate on the metric's timeline, and some AWS metrics arrive with delay, so very short periods can see incomplete data.
An alarm in INSUFFICIENT_DATA is not "fine"; it may mean the resource or agent stopped reporting.
Memory and disk metrics for EC2 are not built in; you need the CloudWatch agent.
How an alarm decides to fire. An alarm needs M breaching data points out of the last N periods before it changes state.
Metric data points arrive: For example ALB 5XX error rate every 60 seconds.
Statistic over each period: Average, Sum, or a percentile such as p99.
Compare with the threshold: Each period is breaching or not breaching.
Check M out of N: 3 of the last 5 periods must breach.
State changes to ALARM: Configured actions run, such as notifying SNS.
Recovery to OK: Optional OK action sends the all-clear.
Fires when more than 20 target 5XX errors happen in at least 3 of the last 5 minutes. Missing data counts as healthy because the metric is absent when there are no errors.
Key points
Three states: OK, ALARM, INSUFFICIENT_DATA
Period, threshold, evaluation periods, and datapoints to alarm (M out of N) control sensitivity
Actions: SNS, EC2 actions, Auto Scaling, Lambda, Systems Manager
Composite alarms combine alarms; anomaly detection learns a normal band
EC2 memory and disk metrics need the CloudWatch agent
Common follow-up questions
How would you alert on error rate instead of raw error count?
What does treat-missing-data do and when would you set it to breaching?
How do composite alarms reduce alert noise?
How do Auto Scaling target tracking policies use CloudWatch alarms?
Interview tips
Walk through the evaluation settings (period, M out of N, missing data); that is where real experience shows
Talk about alerting on user-facing symptoms and reducing noise, not just 'CPU above 80%'
Share a concrete alarm you would set for an API, including the action it triggers