-
-
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
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
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