Skip to content

Instantly share code, notes, and snippets.

@BalajiVelaga
Forked from g-a-d/lambda_handler.py
Created August 22, 2021 06:55
Show Gist options
  • Save BalajiVelaga/288a35755f196a9ff8083145e6ffd93b to your computer and use it in GitHub Desktop.
Save BalajiVelaga/288a35755f196a9ff8083145e6ffd93b to your computer and use it in GitHub Desktop.
Process either S3 event notifications or SNS messages with python in AWS Lambda
import urllib
def lambda_handler(event, context):
for record in event['Records']:
try:
if 'aws:sns' == record['EventSource'] and record['Sns']['Message']:
record = json.loads(record['Sns']['Message'])['Records'][0]
except KeyError:
pass
bucket = record['s3']['bucket']['name']
key = urllib.unquote(record['s3']['object']['key'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment