Create a CloudWatch Event and SNS Notification for your AWS Environment
AWS Training Architect II in Content
In this learning activity we will create a CloudWatch alarm that triggers an SNS email notification. Then we will trigger the alarm by simulating the shutdown of an EC2 instance.
Create a CloudWatch Event and SNS Notification for Your AWS Environment
In this lab, we will create a CloudWatch alarm that triggers a Simple Notification Service (SNS) email notification. Then we will trigger the alarm by simulating the shutdown of an EC2 instance.
Log in to the AWS Management Console using the credentials provided on the lab instructions page. Make sure you are using the us-east-1 region.
Triggering an SNS Topic with a CloudWatch Event
Create an SNS Topic
First, we need to create an SNS topic and subscribe to it.
- In the AWS Management Console, navigate to the Simple Notification Service (SNS).
- Click Get started.
- On the SNS dashboard page, click Create topic.
- For Topic name, type "EssentialsCWEvent".
- Click Create topic.
- Next, click Create subscription.
- In the Create subscription menu, change the Protocol to Email.
- For Endpoint, type your email address.
- Click Create subscription.
- In a new browser tab, navigate to your email inbox.
- Open the AWS Subscription Confirmation email, and click the Confirm subscription link.
- Go back to your AWS Management Console browser tab, and refresh to page. The subscription should now be confirmed.
Create a CloudWatch Event Task to Trigger the SNS Topic
Create a CloudWatch Event Rule
Now we need to create a CloudWatch event that will trigger the SNS topic.
- Navigate to the CloudWatch service.
- Click Events in the left sidebar.
- Click Create rule.
- Under Event Source, leave the Event Pattern option selected.
- For Service Name, select EC2 from the dropdown.
- For Event Type, select EC2 Instance State-change Notification from the dropdown.
- Next, under Targets, click Add target.
- Click into the field at the top of the Targets menu, and select SNS topic from the dropdown.
- For Topic, select EssentialsCWEvent from the dropdown.
- Click Configure details at the bottom of the page.
- Name the rule "InstanceStateChanges".
- For State, leave the box next to Enabled checked.
- Click Create rule.
Test the CloudWatch Rule
- Navigate to the EC2 service in the AWS Management Console.
- Click 1 Running Instances at the top of the page.
- Click Actions, Change State, then Stop.
- Click Yes, Stop.
- While the instance state is stopping, go back to your email inbox, and check for an email from AWS Notifications.
- Open the email. The message content should indicate that the instance state is currently stopping.
- Go back to the AWS Management Console, and wait for the instance state to be stopped.
- Go back to your email, and check for another email from AWS Notifications.
- Open the email. The message content should indicate that the state is now stopped.
- Go back to the AWS Management Console.
- With the stopped instance selected, click Actions, Instance State, and Start.
- Click Yes, Start.
- Go back to your email inbox, and check for another message from AWS Notifications indicating that the state is pending.
- Finally, you should receive one more email from AWS Notifications when the instance state changes to running.
Congratulations, you've successfully completed this lab!
Note: Please delete your email in the SNS section before closing the lab.