Created
October 4, 2016 17:50
-
-
Save danlindow/719f1c3070fc9718e521d474079b9f34 to your computer and use it in GitHub Desktop.
lambda function to make a pretty SNS notification instead of JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import boto3 | |
print('Loading function') | |
#set region | |
REGION = 'us-west-2' | |
#set the SNS topic ARN you want to alert on | |
SNS_TOPIC_ARN = 'arn:aws:sns:REGION:ACCOUNT_ID:TOPIC_NAME' | |
def lambda_handler(event, context): | |
sns_body = 'Instance {} has changed to {} state at {} UTC'.format(event['detail']['instance-id'], event['detail']['state'], event['time']) | |
client = boto3.client('sns', region_name=REGION) | |
response = client.publish( | |
TopicArn=SNS_TOPIC_ARN, | |
Subject='Instance state change notification', | |
Message=sns_body | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment