Home AWSAWS CloudWatch Alarms for EC2: Setup, Alerts, and Tests

AWS CloudWatch Alarms for EC2: Setup, Alerts, and Tests

by Knowledge Base Linux
AWS CloudWatch alarms EC2

An EC2 instance can run out of disk, exhaust CPU credits, or fail a status check at 3 a.m., and without alarms you only learn about it from users. AWS CloudWatch alarms for EC2 turn metrics into action: they watch CPU, disk, memory where available, and status checks, then notify you or trigger remediation before a small problem becomes an outage. This guide shows how to set up AWS CloudWatch alarms for EC2 that are useful, not noisy.

You will create alarms for high CPU, low disk space via the CloudWatch agent, and failed status checks, wire them to an SNS topic, and test them so you trust them when they fire. The examples use the AWS CLI, which makes the setup repeatable across instances.

AWS CloudWatch alarms EC2 illustration

Prerequisites for AWS CloudWatch Alarms for EC2

You need an AWS account, an EC2 instance running with a monitoring role or credentials for the CloudWatch agent, and the AWS CLI configured. Basic monitoring, with five-minute metric granularity, is enough for most alarms; detailed monitoring at one minute costs more and is worth it only for latency-sensitive services.

Note one important gap: EC2 does not report memory or disk usage by default. Those metrics come from the CloudWatch agent running inside the instance. If you only need CPU and status checks, you can skip the agent; if you need disk alarms, install it first.

Step 1: Create an SNS Topic for Alarm Notifications

Alarms notify through SNS topics, not directly to email addresses. Create a topic, subscribe your email, and confirm the subscription before creating alarms, otherwise notifications are silently dropped:

aws sns create-topic --name ec2-alarms
aws sns subscribe --topic-arn arn:aws:sns:us-east-1:123456789012:ec2-alarms \
  --protocol email --notification-endpoint [email protected]

Check your inbox and confirm the subscription. For a team, subscribe a shared mailbox or a chat integration endpoint instead of one person’s address, so alerts survive vacations and staff changes.

Step 2: Create a CPU Alarm for EC2

Create an alarm that fires when average CPU utilization exceeds 80 percent for three consecutive five-minute periods. Requiring multiple periods prevents a brief spike from paging anyone, while still catching a genuinely overloaded instance:

aws cloudwatch put-metric-alarm \
  --alarm-name ec2-high-cpu-web-01 \
  --alarm-description "High CPU on web-01" \
  --namespace AWS/EC2 \
  --metric-name CPUUtilization \
  --dimensions Name=InstanceId,Value=i-0123456789abcdef0 \
  --statistic Average \
  --period 300 \
  --evaluation-periods 3 \
  --threshold 80 \
  --comparison-operator GreaterThanThreshold \
  --alarm-actions arn:aws:sns:us-east-1:123456789012:ec2-alarms \
  --ok-actions arn:aws:sns:us-east-1:123456789012:ec2-alarms

Set the OK action too, so you get a recovery notification and can tell at a glance whether the incident is over. For burstable instances, also watch CPU credit balance: an alarm on CPUCreditBalance below 20 warns you before throttling starts.

Step 3: Add Disk and Status Check Alarms for EC2

Install the CloudWatch agent on the instance and configure it to collect disk usage, then create a disk alarm. The metric namespace for agent metrics is CWAgent, and the dimension includes the instance ID and the mount path:

sudo apt update && sudo apt install -y amazon-cloudwatch-agent
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
  -a fetch-config -m ec2 -c ssm:AmazonCloudWatch-linux -s
aws cloudwatch put-metric-alarm \
  --alarm-name ec2-low-disk-web-01 \
  --alarm-description "Root disk above 85 percent on web-01" \
  --namespace CWAgent \
  --metric-name disk_used_percent \
  --dimensions Name=InstanceId,Value=i-0123456789abcdef0 Name=path,Value=/ \
  --statistic Average \
  --period 300 \
  --evaluation-periods 2 \
  --threshold 85 \
  --comparison-operator GreaterThanThreshold \
  --alarm-actions arn:aws:sns:us-east-1:123456789012:ec2-alarms

Status check alarms need no agent. Create one on StatusCheckFailed with a threshold of 1 for a single period, because any failed status check deserves attention immediately:

aws cloudwatch put-metric-alarm \
  --alarm-name ec2-status-check-web-01 \
  --alarm-description "Status check failed on web-01" \
  --namespace AWS/EC2 \
  --metric-name StatusCheckFailed \
  --dimensions Name=InstanceId,Value=i-0123456789abcdef0 \
  --statistic Maximum \
  --period 60 \
  --evaluation-periods 1 \
  --threshold 1 \
  --comparison-operator GreaterThanOrEqualToThreshold \
  --alarm-actions arn:aws:sns:us-east-1:123456789012:ec2-alarms

Step 4: Test Your AWS CloudWatch Alarms for EC2

An untested alarm is a guess. Force an alarm into the ALARM state temporarily and confirm the notification arrives, then return it to normal:

aws cloudwatch set-alarm-state \
  --alarm-name ec2-high-cpu-web-01 \
  --state-value ALARM \
  --state-reason "Testing alarm notifications"
aws cloudwatch describe-alarms --alarm-names ec2-high-cpu-web-01

Check that the email or chat message arrived, then let the alarm recover naturally or set it back to OK. Repeat this test after any change to the SNS topic, and document the expected notification path in your runbook so on-call staff know what an alarm means and what to do first.

Troubleshooting AWS CloudWatch Alarms for EC2

If an alarm never fires, check the metric first in the CloudWatch console: a wrong instance ID, wrong namespace, or wrong dimension produces a flat line with no data, and alarms on missing data default to not firing. Use aws cloudwatch list-metrics --namespace AWS/EC2 to confirm the metric actually exists for your instance.

If alarms fire constantly, the threshold is wrong for the workload, not the alarm. A batch server that legitimately runs at 90 percent CPU all day needs a higher threshold or an anomaly detection alarm, not a muted alarm. Conversely, if you muted an alarm because it was noisy, fix the threshold and unmute it the same day, or the next real incident will be silent too.

If notifications do not arrive, check the SNS subscription status first: unconfirmed subscriptions receive nothing, and there is no error in CloudWatch to tell you. Then check that the alarm action ARN matches the topic in the same region, because a cross-region ARN typo fails silently.

Conclusion

AWS CloudWatch alarms for EC2 are most valuable when they are few, tested, and tied to action: CPU for overload, disk for capacity, and status checks for instance health, all routed through one SNS topic your team actually monitors. Start with those three, test the notification path, and add more only when an incident shows a gap. For deeper log analysis, see our guide on CloudWatch Logs Insights for EC2 and our overview of EBS volume types. The official CloudWatch alarms documentation covers composite alarms and automated remediation actions.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.