Monitoring and Notifications with CloudWatch Events and SNS

Hands-On Lab

 

Photo of Julie  Elkins

Julie Elkins

AWS Training Architect I in Content

Length

00:30:00

Difficulty

Beginner

In this hands-on lab, we will create a CloudWatch Events 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.

Monitoring and Notifications with CloudWatch Events and SNS

Introduction

In this hands-on lab, we will create a CloudWatch Events alarm that triggers an SNS email notification. Then, we will trigger the alarm by simulating the shutdown of an EC2 instance.

Solution

Log in to the live AWS environment using the credentials provided. Make sure you're in the N. Virginia (us-east-1) region throughout the lab.

Create an SNS Topic and Subscribe an Email Address

  1. In the AWS Management Console, navigate to Simple Notification Service (SNS).
  2. In the Create topic box, enter a Topic name of "EC2statechange".
  3. Click Next step.
  4. On the Create topic page, leave everything as default and click Create topic.
  5. In the Subscriptions section, click Create subscription.
  6. On the Create subscription page, change the Protocol to Email.
  7. For Endpoint, type your email address.
  8. Click Create subscription.
  9. In a new browser tab, navigate to your email inbox.
  10. Open the AWS Notification - Subscription Confirmation email, and click the Confirm subscription link.
  11. Go back to your AWS Management Console browser tab, and refresh the page. The subscription should now be confirmed.

Create a CloudWatch Events Rule to Trigger the SNS Topic When There Is a State Change to an EC2 Instance

  1. Navigate to CloudWatch.
  2. Click Events in the left-hand menu.
  3. Click Get started.
  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. Leave the Any state and Any instance options selected.
  8. Under Targets, click Add target.
  9. Click into the field at the top of the Targets menu, and select SNS topic from the dropdown.
  10. For Topic, select EC2statechange from the dropdown.
  11. Click Configure details at the bottom of the page.
  12. Name the rule "EC2instancestatechange".
  13. For State, leave the box next to Enabled checked.
  14. Click Create rule.

Change the State of the EC2 Instance, and Verify Receipt of the SNS Notification

  1. Navigate to EC2.
  2. Click 1 Running Instances at the top of the page.
  3. With the instance selected, click Actions > Instance State > 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.

Conclusion

Congratulations — you've successfully completed this hands-on lab!