How to Send Alert Emails Based on Your AWS Instance CPU Usage Alarm

How to Send Alert Emails Based on Your AWS Instance CPU Usage Alarm

Amazon CloudWatch is used for basic monitoring of several AWS products. It monitors various services based on available AWS cloud metrics. We can set an alert using the AWS SNS service to send an email if some service is not behaving as expected. This guide shows how to send an email based on the CPU usage of EC2 instances.

1. Enter the AWS UI console and get the ID of the running instance.

2. To access the AWS CloudWatch console go to the AWS console and select the AWS CloudWatch service. The dashboard will list your present alarms as well as an overview of your AWS resources. Click “View Metrics”.

3. The metrics available with CloudWatch for your account will be loaded. Select “EC2: Instance Metrics” from the “viewing” drop down menu to list the metrics available for all the instances of the current region. Selecting CPUUtilization for any instance it will show the CPUUtilization graph for that instance. Click “Create Alarm” to set an alarm based on the CPU Utilization metric of the selected instance.

[Newvem analyzes your baseline disaster recovery (DR) status, reflecting how well AWS DR best practices have been implemented, and recommends AWS features and best practices to reach optimal availability, increase outage protection, and quick recovery. Learn more about Newvem analytic features]

4. Provide Name & Description of the new alert created. In “Define Alarm Threshold”, provide the threshold value and period to set the alarm on. In the case below, when the CPU Utilization is more than 70% for 5 minutes than the state of the alert changes to ALARM. Click “Continue”.

5. CloudWatch can send emails using the SNS service. Any CloudWatch alert has three stages, ALARM, Ok & Insufficient Data. You can set the action for each of the states.

6. When you select “Send or Create Email Topic” it will ask you for the target email address. Provide one or multiple email IDs (comma separated). If you want to set an alarm for any other state like “OK” or “Insufficent Data” click “Add Action”.

7. It will add a new row. Configure action and action details for the second state. If you do not want to configure action for any other state click “Continue”.

8. Review all the parameters you provided in the previous screen. If all the parameters are correct, click “Create Alarm”.

9. It will create the alarm and show the confirmation page. Click “Close”.

10. When the alarm is created and it is configured to send the email for any state, CloudWatch will send a confirmation mail to that email ID for verification. To confirm, click “Confirm Subscription”.

11. Click on CloudWatch dashboard inside the CloudWatch console. It will list the new alert as well as the current state of the alarm.

12. If you want to set an alarm for some other metric other than CPU Utilization, select that metric instead of CPU Utilization in step#3 and configure the alarm as explained above. For the list of all available metrics for any AWS service check here.

Add a CloudWatch Alert Using the CLI Tools

13. If you want to add an alert using command line tool you need to install CLI. You will also need the ARN ID of your SNS topic.

14. Run the commands below.

First set the Region for CloudWatch:


Run command:

mon-put-metric-alarm --alarm-name cpu-monitor --alarm-description "Alarm sends Email when CPU exceeds 70" --metric-name CPUUtilization --namespace AWS/EC2 --statistic Average --period 60 --threshold 70 --comparison-operator GreaterThanThreshold --dimensions "InstanceId=i-06ab5d3e" --evaluation-periods 2 --unit Percent --alarm-actions arn:aws:sns:us-west-2: xxxxxxxxxxxx:CPU_Utilization_More_Than_70

The above command creates an alarm for CPU Utilization. If you want to change the state of the alarm manually try the following command:

mon-set-alarm-state cpu-monitor --state-reason "initializing" --state-value OK

The above command changes the state of the alert to “OK”.

mon-set-alarm-state cpu-monitor --state-reason "testing" --state-value ALARM

The above command changes the state of the alert to “ALARM”.

15. The actual output of the above commands is shown below.

We observed that sometimes although your syntax is correct the CloudWatch API throws an error message saying that the syntax is incorrect.

Check your environment variable through the set command. If it has any ARGV variable set, reset it with command


Note : We did provide a blank value to ARGV to reset it.

[Newvem analytics tracks you AWS cloud utilization:

Create Your Free Account or Learn More about Newvem's features]

Keywords: Amazon web services, Amazon AWS console, Amazon AWS instances, EC2 Service, Amazon cloud computing, EC2 EBS, EC2 CPU Utilization, AWS Infrastructure Elasticity, Amazon EC2 capacity, Cloud Monitoring, CloudWatch, API, CLI tools, CloudWatch Alarm, EC2 Instance

You must be to post a comment.

* As a bonus, you'll receive our weekly newsletter!

Hitchhiker's Guide to The Cloud

Newvem's eBook for Cloud Operations