Skip to content

Instantly share code, notes, and snippets.

@mnanchev
Forked from danlindow/prettify.py
Created February 10, 2022 19:20
Show Gist options
  • Save mnanchev/59eadcd42a0d23af5cbedeff377d17d7 to your computer and use it in GitHub Desktop.
Save mnanchev/59eadcd42a0d23af5cbedeff377d17d7 to your computer and use it in GitHub Desktop.
lambda function to make a pretty SNS notification instead of JSON
#!/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