Skip to content

Instantly share code, notes, and snippets.

@mgdombrowski
Last active October 31, 2017 17:18
Show Gist options
  • Save mgdombrowski/342e5110a44210f20db892a60b646762 to your computer and use it in GitHub Desktop.
Save mgdombrowski/342e5110a44210f20db892a60b646762 to your computer and use it in GitHub Desktop.
import base64
import json
import boto3
snsClient = boto3.client('sns')
print('Loading function')
def lambda_handler(event, context):
for record in event['Records']:
# Kinesis data is base64 encoded so decode here
# payload = json.loads(base64.b64decode(record['kinesis']['data']))
payload = base64.b64decode(record['kinesis']['data'])
print payload
response = snsClient.publish(
TopicArn='arn:aws:sns:us-east-1:964214137428:heartanomalies',
Message='A possible heart anomaly was detected. Are you ok?' + payload + '\nClick here to let us know:\n http://heartnotification.com',
Subject='Anomaly detected',
MessageStructure='string',
MessageAttributes={
'String': {
'DataType': 'String',
'StringValue': 'New records have been processed.'
}
}
)
return 'Successfully processed {} records.'.format(len(event['Records']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment