O'Reilly logo

Python and AWS Cookbook by Mitch Garnaat

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting Notifications

Problem

You have monitoring enabled on your EC2 instance. Now you would like to get notified when certain conditions arise.

Solution

Use CloudWatch Alarms to set up notification.

Discussion

All of the recipes in this book are focused on the EC2 and S3 services. However, for this particular recipe we will dip our toe into one other Amazon Web Service, the Simple Notification Service. This service provides a very simple yet robust publish and subscribe service, which does a great job as a scalable method of implementing communication between processes or services. We won’t be able to cover the details of SNS in detail, but this example will show you how to leverage SNS to quickly enable email notification of CloudWatch events using alarms.

The following commands assume that you have signed up for SNS with your AWS account. The first step in enabling CloudWatch alarms is to create an SNS topic to which events can be published. People or systems that are interested in these events can then subscribe to the topic. When you subscribe, you can select a number of different notification protocols. For example, you could select http, which would cause a JSON payload containing the message contents to be POSTed via HTTP to the endpoint you provide. Or you can subscribe via SQS (Simple Queue Service), which will place a message in an SQS queue. For this example, we will use the email protocol to send an email message to the specified email address each time an alarm is fired. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required