Print
Category: Technical
Hits: 5957

Monitoring via Twitter - it's something you've always dreamed of!

When setting up your CloudWatch Alarms, you'll notice that there are a number of possible destinations for your SNS Topic.  For direct notification to an individual, out of the box, the easiest of these are either SMS (which costs money) or Email (which might be down if the system you're monitoring handles email).

Fortunately, AWS offers other SNS targets too, including Lambda (which we'll use here).  So let's use a totally unrelated mechanism for alerting ourselves, via Twitter Direct Message!  The big benfit of this is that it will get you push notifications to your phone (assuming you're using a Twitter app) for high priority issues.

The code for this is located here on GitHub, and we will use the Serverless framework to deploy it.

Check the code out, and start with the twitter.json file, we'll need to issue Twitter credentials to fill this out.  To generate these visit https://developer.twitter.com/en/apps and "Create an app".  Take the API key details and complete the twitter.json file with them.

Edit serverless.yml and set the TWITTER_USERS value to a comma separated (no spaces) list of Twitter users to send the direct message to.

Run setup.sh - this will store your twitter credentials in an encrypted string in SSM Parameter Store so that the Lambda function can retrieve them when it runs.  The setup script will also install the python-twitter module into your working directory to be included with your Lambda function.

Deploy your lambda function and SNS topic using serverless deploy

Now, when you create CloudWatch alarms you can choose the SNS topic TwitterNotify to send the alerts to, and they'll be DMed to you via Twitter.

Exciting stuff!