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.
(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.
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.
Select the created topic, and from there, click on “Create Subscription” under the “Subscriptions” section to create a subscription.
Select “E-mail” as the “Protocol.” After selecting it, enter the email address where you want to receive the notifications in the “Endpoint” field.
Check your inbox and approve this subscription from the received email. After approval, verify that the “Status” is “Confirmed” for the subscription.
(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.
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.
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.
Select “Select an existing SNS topic” and choose the topic you created in step (1) as the “Send a notification to” destination.
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.
Make sure that the “Status” becomes “OK“.
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.
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.