How to Send Emails Alert Based on AWS Elastic Load Balancer Alarms

How to Send Emails Alert Based on AWS Elastic Load Balancer Alarms

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 a service is not behaving as expected.

Learn how to send an email when the CPU Utilization exceeds a threshold value. This guide shows how to send an email based on an ELB (Elastic Load Balancer) metrics.

Login to your AWS UI console and follow the next steps:

1. Go to the AWS EC2 console and get the Load Balancer details. Write down the ELB Name.

2. Enter the AWS CloudWatch console  and select the AWS CloudWatch service. The dashboard list your present alarms as well as an overview of your AWS resources alarms. Click on “View Metrics”.

3. The  metrics available with CloudWatch will be loaded. Select “ELB: Load Balancer Metrics” from the “Viewing” drop down menu.

[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's features]

4. The metrics available for all the ELBs in the current AWS region will be loaded. Select the ELB Name and any of irs related metrics. It will show the graph of the selected metric at the bottom. Click “Create Alarm” to set a new alarm for the selected ELB metric.

5. Provide the metadata for defining the alert. Provide the Name and Description. In “Define Alarm Threshold”, provide the threshold value and period to have the alarm on. In the case below we configured that if the ELB Unhealthy Host Count is more than 3 for 2 minutes the state of the alert will change to ALARM. Click “Continue”.

6. Configure the action for that alert. CloudWatch sends emails using the SNS service. Any CloudWatch alert has three stages, ALARM, Ok & Insufficient Data. You can set an action for each of the states. To send an email when the state is set to ALARM, select the state as “ALARM”, then in “Action” specify “Send Notification” and in “Topic” select “Select or create email topic”.

7. When you select “Select or create email topic” it will ask you for the email address which will receive the message. Provide one or multiple email IDs (comma separated). Click “Continue”.

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

9. On the confirmation page click “Close”.

10. Click on “Alarms” in left menu of the CloudWatch console. Your new alert will be shown with its current state.

11. When the alarm is created and configured to send emails for any state, CloudWatch sends a confirmation email verification to the the assigned email. Acknowledge by clicking “Confirm Subscription”.

12. Once you confirmed the subscription, you will be forwarded to the following screen.

13. If you want to set alarm an for any other metric than Unhealthy Host Count, select that metric instead of Unhealthy Host Count in step#2 and configure the alarm as shown above. Check the list of all the available metrics for any AWS service

 Generate Emails Alerts Based on AWS ELB Alarms using the AWS CLI (command line tools)

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

15. Run the commands below.

Start by setting the Region for CloudWatch:


Run the command:

mon-put-metric-alarm --alarm-name elb-unhelathy --alarm-description "Alarm sends Email when ELB Unhealthy Count Increases" --metric-name UnHealthyHostCount --namespace AWS/ELB --statistic Average --period 120 --threshold 3 --comparison-operator GreaterThanThreshold --dimensions "LoadBalancerName=CloudWatchAlarm" --evaluation-periods 2 --unit Count --alarm-actions arn:aws:sns:us-west-2:xxxxxxxxxxxx:SendEmail

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 elb-unhelathy --state-reason "initializing" --state-value OK

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

mon-set-alarm-state elb-unhelathy --state-reason "testing" --state-value ALARM

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

16. The actual output of all 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 not provide a blank value to ARGV to reset it.

17. If the Alarm state gets changed to ALERT it will send an email to to email ID configured in the SNS topic or mentioned in step#7 as shown below.

[Newvem analytics tracks you AWS cloud utilization:

Create Your Free Account or Learn more about Newvem analytic 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, Amazon SNS,

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