Create a CloudWatch Event and SNS Notification for your AWS Environment

Hands-On Lab

 

Photo of Tia  Williams

Tia Williams

AWS Training Architect II in Content

Length

00:30:00

Difficulty

Beginner

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.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Create a CloudWatch Event and SNS Notification for Your AWS Environment

Introduction

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.

  1. In the AWS Management Console, navigate to the Simple Notification Service (SNS).
  2. Click Get started.
  3. On the SNS dashboard page, click Create topic.
  4. For Topic name, type "EssentialsCWEvent".
  5. Click Create topic.
  6. Next, click Create subscription.
  7. In the Create subscription menu, change the Protocol to Email.
  8. For Endpoint, type your email address.
  9. Click Create subscription.
  10. In a new browser tab, navigate to your email inbox.
  11. Open the AWS Subscription Confirmation email, and click the Confirm subscription link.
  12. 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.

  1. Navigate to the CloudWatch service.
  2. Click Events in the left sidebar.
  3. Click Create rule.
  4. Under Event Source, leave the Event Pattern option selected.
  5. For Service Name, select EC2 from the dropdown.
  6. For Event Type, select EC2 Instance State-change Notification from the dropdown.
  7. Next, under Targets, click Add target.
  8. Click into the field at the top of the Targets menu, and select SNS topic from the dropdown.
  9. For Topic, select EssentialsCWEvent from the dropdown.
  10. Click Configure details at the bottom of the page.
  11. Name the rule "InstanceStateChanges".
  12. For State, leave the box next to Enabled checked.
  13. Click Create rule.

Test the CloudWatch Rule

  1. Navigate to the EC2 service in the AWS Management Console.
  2. Click 1 Running Instances at the top of the page.
  3. Click Actions, Change State, then Stop.
  4. Click Yes, Stop.
  5. While the instance state is stopping, go back to your email inbox, and check for an email from AWS Notifications.
  6. Open the email. The message content should indicate that the instance state is currently stopping.
  7. Go back to the AWS Management Console, and wait for the instance state to be stopped.
  8. Go back to your email, and check for another email from AWS Notifications.
  9. Open the email. The message content should indicate that the state is now stopped.
  10. Go back to the AWS Management Console.
  11. With the stopped instance selected, click Actions, Instance State, and Start.
  12. Click Yes, Start.
  13. Go back to your email inbox, and check for another message from AWS Notifications indicating that the state is pending.
  14. Finally, you should receive one more email from AWS Notifications when the instance state changes to running.

Conclusion

Congratulations, you've successfully completed this lab!