Skip to content

Instantly share code, notes, and snippets.

View pauloapi's full-sized avatar
:octocat:

Paulo Rodriguez pauloapi

:octocat:
View GitHub Profile
@pauloapi
pauloapi / get_lambda_event_source.py
Last active October 10, 2022 17:08
AWS Lambda: Determine Event Source from event object. Based on this javascript gist https://gist.github.com/jeshan/52cb021fd20d871c56ad5ce6d2654d7b
def get_lambda_event_source(self, event: dict):
if 'pathParameters' in event and 'proxy' in event['pathParameters']:
return 'api_gateway_aws_proxy'
if 'requestContext' in event and 'resourceId' in event['requestContext']:
return 'api_gateway_http'
elif 'Records' in event and len(event['Records']) > 0 and 'eventSource' in event['Records'][0] and event['Records'][0]['eventSource'] == 'aws:s3':
return 's3'
elif 'Records' in event and len(event['Records']) > 0 and 'EventSource' in event['Records'][0] and event['Records'][0]['EventSource'] == 'aws:sns':
return 'sns'