How to implement email notifications with CloudWatch alarms and SNS
Introduction
CloudWatch alarms monitor various metrics and trigger alerts when they exceed pre-set thresholds. On the other hand, SNS (Simple Notification Service) is a service that delivers notifications to different endpoints, including email notifications, offering various notification methods.
In this blog, we will explain step-by-step how to combine CloudWatch alarms with SNS to detect specific events or issues and receive email notifications at the appropriate timing. We will also provide detailed instructions on how to set up alarms, create SNS topics, and configure email notifications.
Building procedure
(1) Create SNS Topic and Subscription
To create an Amazon SNS topic and subscription, click on “Topics” from the Amazon SNS dashboard, and then click “Create Topic” at the top right corner. This will take you to the screen where you can create a new topic.
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像1-1-840x222.png)
First, enter the “Name” for the topic. Then, select the “Type” as “Standard,” and finally, click on “Create Topic” at the bottom right corner to create the topic.
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像2-347x360.png)
Select the created topic, and from there, click on “Create Subscription” under the “Subscriptions” section to create a subscription.
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像3-1-840x204.png)
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像4-2-547x360.png)
Select “E-mail” as the “Protocol.” After selecting it, enter the email address where you want to receive the notifications in the “Endpoint” field.
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像5-2-529x360.png)
Check your inbox and approve this subscription from the received email. After approval, verify that the “Status” is “Confirmed” for the subscription.
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像6-1-514x360.png)
(2) Creating a CloudWatch Alarm
From the CloudWatch dashboard, click on “Alarms“, and then click “Create Alarm” at the top right corner. This will take you to the screen where you can create a new alarm.
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像7-1-840x252.png)
Click on “Select metric” and then choose “Per-Instance Metrics” under “EC2“. Select the CPU utilization metric for the specific EC2 instance, and click on “Select metric” at the bottom right corner.
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像8-1.png)
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像9-490x360.png)
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像10-1-675x360.png)
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像11-1-356x360.png)
After selecting the CPU utilization metric for the specific EC2 instance, set the condition that the alarm will trigger if the CPU utilization exceeds 70 for one minute. Once you have set this condition, click on “Next” at the bottom right corner.
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像12-303x360.png)
Select “Select an existing SNS topic” and choose the topic you created in step (1) as the “Send a notification to” destination.
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像13-1-318x360.png)
Enter the “Alarm name“, and then click on “Next“. Review the alarm settings, and once you have confirmed the details, click on “Create Alarm” at the bottom right corner to create the alarm.
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像14-1-827x360.png)
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像15-293x360.png)
Make sure that the “Status” becomes “OK“.
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像16-840x120.png)
In this case, if the CPU utilization exceeds 70 for one minute, the “State” will change to “Alarm” and, upon confirming the email notification, if everything is fine, the creation process will be completed without any issues.
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像17-840x172.png)
![](http://www.atmarksol.jp/wp-content/uploads/2023/07/画像18.jpg)
Conclusion
By implementing email notifications through CloudWatch alarms and SNS, the efficiency of system monitoring and incident response can be significantly improved. Real-time detection of issues and timely notifications to relevant stakeholders enable early identification of problems and swift responses to incidents.
In this session, we learned the basics of using CloudWatch alarms and SNS. In the future, you can build more advanced monitoring systems to further enhance the stability and availability of your system.