Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AWS Lambda: Determine Event Source from event object. Note that this is an approximation as anybody can send a payload that resembles the real thing.
function getLambdaEventSource(event) {
if (event.Records && event.Records[0].cf) return 'isCloudfront';
if (event.configRuleId && event.configRuleName && event.configRuleArn) return 'isAwsConfig';
if (event.Records && (event.Records[0].eventSource === 'aws:codecommit')) return 'isCodeCommit';
if (event.authorizationToken === "incoming-client-token") return 'isApiGatewayAuthorizer';
if (event.StackId && event.RequestType && event.ResourceType) return 'isCloudFormation';
if (event.Records && (event.Records[0].eventSource === 'aws:ses')) return 'isSes';
if (event.pathParameters && event.pathParameters.proxy) return 'isApiGatewayAwsProxy';
if (event.source === 'aws.events') return 'isScheduledEvent';
if (event.awslogs && event.awslogs.data) return 'isCloudWatchLogs';
if (event.Records && (event.Records[0].EventSource === 'aws:sns')) return 'isSns';
if (event.Records && (event.Records[0].eventSource === 'aws:dynamodb')) return 'isDynamoDb';
if (event.records && event.records[0].approximateArrivalTimestamp) return 'isKinesisFirehose';
if (event.records && event.deliveryStreamArn && event.deliveryStreamArn.startsWith('arn:aws:kinesis:')) return 'isKinesisFirehose';
if (event.eventType === 'SyncTrigger' && event.identityId && event.identityPoolId) return 'isCognitoSyncTrigger';
if (event.Records && event.Records[0].eventSource === 'aws:kinesis') return 'isKinesis';
if (event.Records && event.Records[0].eventSource === 'aws:s3') return 'isS3';
if (event.operation && event.message) return 'isMobileBackend';
if (event.Records && (event.Records[0].eventSource === 'aws:sqs')) return 'isSqs';
}
@silvav

This comment has been minimized.

Copy link

@silvav silvav commented Apr 15, 2018

I would like to show this code block on my master thesis. Can you confirm that this code is licensed under public domain?
Alternatively, could you grant me permission to publish it?

@CowChris

This comment has been minimized.

Copy link

@CowChris CowChris commented Apr 25, 2019

For SQS:

if (event.Records && (event.Records[0].eventSource === 'aws:sqs')) return 'isSqs';

@jeshan

This comment has been minimized.

Copy link
Owner Author

@jeshan jeshan commented Dec 10, 2019

Guys, this slipped under my radar. I don't know why github does not send notifications for gists.
silvav: if it's still relevant for you, then yes you can use it under public domain.
CowChris: thanks, I'll add it

@Necromancerx

This comment has been minimized.

Copy link

@Necromancerx Necromancerx commented May 7, 2020

For Python: You can check this out https://gist.github.com/Necromancerx/abed07138690d37d170a6cf15b40d749. This is just based on your gist. Thank you.

@Cevinlo88

This comment has been minimized.

Copy link

@Cevinlo88 Cevinlo88 commented Oct 30, 2020

Would you kindly add a if statement for a lambda being triggered by application load balancer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.