Home AWSHow to Monitor EC2 Instances with CloudWatch Alarms and SNS

How to Monitor EC2 Instances with CloudWatch Alarms and SNS

by Knowledge Base Linux
How to Monitor EC2 Instances with — How to Monitor EC2 Instances with CloudWatch Alarms and SNS

Learning how to use cloudwatch alarms ec2 monitoring properly is the difference between discovering an outage from your monitoring system and discovering it from angry customers. EC2 instances can run out of CPU, fill their disks, or fail status checks at any hour. Amazon CloudWatch collects metrics from every instance, and with the right cloudwatch alarms ec2 configuration plus SNS notifications, you are alerted within minutes and can even trigger automatic recovery. This guide walks you through metrics, the CloudWatch agent, SNS topics, and practical alarms step by step. This article covers How to Monitor EC2 Instances with in detail.

This tutorial builds on a running instance — if you need one, follow our EC2 launch guide first and browse the AWS category for related guides. Official background is in the Amazon CloudWatch documentation.

How CloudWatch Alarms EC2 Monitoring Works – How to Monitor EC2 Instances with

Understanding how cloudwatch alarms ec2 monitoring works helps you choose the right thresholds. CloudWatch is a monitoring service that stores metrics as time-series data. By default, EC2 sends metrics such as CPUUtilization, NetworkIn, NetworkOut, DiskReadBytes, and StatusCheckFailed every five minutes at no extra cost. Detailed monitoring shortens that interval to one minute for a small charge and is strongly recommended for production servers because a five-minute blind spot is long enough for a traffic spike to become an outage.

An alarm watches a single metric over a period you define. When the metric breaches a threshold for the specified number of evaluation periods, the alarm enters ALARM state and can send an SNS notification, reboot or recover the instance, or trigger Auto Scaling and Lambda actions. When the metric returns to normal, the alarm returns to OK and can notify you again, closing the loop.

Prerequisites – How to Monitor EC2 Instances with

  • One or more running EC2 instances (Linux in this guide)
  • An IAM role attached to the instance with CloudWatchAgentServerPolicy if you will install the agent
  • An email address for SNS notifications
  • AWS CLI v2 configured for the CLI examples
  • Basic familiarity with the AWS Console

Step 1: Enable Detailed Monitoring

  1. Open EC2 > Instances and select your instance.
  2. During launch, detailed monitoring can be enabled under Advanced details. For a running instance, note that the one-minute interval is set at launch or via the monitoring configuration — plan it before production use.
  3. Verify in CloudWatch > Metrics > EC2 that data points arrive every minute.

Detailed monitoring is inexpensive compared with the cost of downtime, and it makes your alarms react three to five times faster.

Step 2: Install the CloudWatch Agent for Memory and Disk Metrics

By default EC2 does not report memory usage or free disk space, because those live inside the operating system. The unified CloudWatch agent fills that gap — essential for a complete cloudwatch alarms ec2 setup.

  1. Attach the IAM role with CloudWatchAgentServerPolicy to the instance.
  2. Install the agent on Ubuntu:
wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
sudo dpkg -i amazon-cloudwatch-agent.deb
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json
systemctl status amazon-cloudwatch-agent

In the wizard, accept memory and disk metrics. Within a few minutes, new metrics appear under CloudWatch > Metrics > CWAgent, including mem_used_percent and disk_used_percent. These two metrics catch the most common real-world failures: memory leaks and full disks from logs.

cloudwatch alarms ec2 alert notification with SNS email illustration
SNS notifications deliver CloudWatch alarm alerts straight to your inbox.

Step 3: Create an SNS Topic and Email Subscription

SNS is the notification backbone for your cloudwatch alarms ec2 workflow.

  1. Open Amazon SNS > Topics > Create topic, choose Standard, and name it ec2-alerts.
  2. Open the topic and choose Create subscription.
  3. Select Protocol: Email, enter your address, and create the subscription.
  4. Check your inbox and click the confirmation link — alarms will not be delivered until the subscription is confirmed.
  5. Copy the topic ARN; you will need it for console and CLI alarm creation.

For teams, subscribe a shared mailing list or connect SNS to Slack or PagerDuty later. Start with email, confirm it works, then expand.

Creating CloudWatch Alarms EC2 Admins Rely On

Now create the three alarms every instance should have. This section on creating cloudwatch alarms ec2 admins rely on covers CPU, status checks, and memory.

Alarm 1: High CPU

  1. Go to CloudWatch > Alarms > Create alarm > Select metric > EC2 > Per-Instance Metrics > CPUUtilization for your instance.
  2. Set Statistic: Average, Period: 5 minutes.
  3. Condition: Greater than 80 percent, for 2 out of 2 datapoints.
  4. Notification: send to the ec2-alerts SNS topic on ALARM and OK.
  5. Name it ec2-high-cpu and create it.

Alarm 2: Status Check Failed

Repeat the flow with metric StatusCheckFailed, threshold greater than or equal to 1 for 2 datapoints. Add an EC2 action to reboot or recover the instance automatically — this single alarm resolves many transient hardware issues without human intervention.

Alarm 3: Memory Usage

Use the CWAgent metric mem_used_percent, threshold greater than 85 percent for 3 datapoints, notified via the same SNS topic. Add a matching disk_used_percent alarm at 85 percent while you are here.

Create Alarms with the AWS CLI

Automate alarm creation so every new server gets the same protection:

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

Replace the instance ID and SNS ARN with your own values. Script this once and reuse it in your launch templates or user-data so no instance ever runs unmonitored.

Alarm Actions: Notify, Reboot, and Recover

Beyond notifications, CloudWatch can act. For StatusCheckFailed you can choose Reboot, Stop, Terminate, or Recover. Recover migrates the instance to new hardware while keeping its instance ID, EBS volumes, and Elastic IP — ideal for instances with instance-store dependencies documented in AWS guidance. Use reboot for software hangs, recover for hardware failures, and always pair any automatic action with an SNS notification so you know it happened. Test every alarm safely by temporarily setting a low threshold, for example CPU greater than 1 percent, confirming the email arrives, then restoring the real threshold.

Troubleshooting CloudWatch Alarms

No email received: Confirm the SNS subscription is confirmed, check spam folders, and verify the alarm actually entered ALARM state in its history.

Memory metric missing: Check the agent service is running, the IAM role is attached, and the agent config includes memory metrics.

Alarm stuck in INSUFFICIENT_DATA: The instance may be stopped, detailed monitoring may be off, or the metric namespace or dimensions in the CLI command may be wrong.

Too many false alarms: Increase evaluation periods, use Average instead of Maximum for CPU, and tune thresholds to your real baseline instead of copying generic values.

Conclusion

You now have a complete cloudwatch alarms ec2 monitoring setup: detailed monitoring enabled, the CloudWatch agent reporting memory and disk, an SNS topic delivering email alerts, and practical alarms for CPU, status checks, memory, and disk — created both in the console and with the CLI. Add automatic reboot or recover actions for status checks, test your alarms once, and review thresholds monthly as your workload grows. Monitoring is not a one-time task, but with this foundation your EC2 fleet will tell you when it needs help, long before your users have to.

You may also like

KbLinux

Typically replies within a day

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