Created
June 10, 2022 13:44
-
-
Save alanshaw/dbecbf2b5e05114702914d51bb2e04e9 to your computer and use it in GitHub Desktop.
SNSEvent to S3Event
This file contains hidden or 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
/** | |
* Extract an S3Event from the passed SNSEvent. | |
* @param {import('aws-lambda').SNSEvent} snsEvent | |
* @returns {import('aws-lambda').S3Event} | |
*/ | |
function toS3Event (snsEvent) { | |
const s3Event = { Records: [] } | |
for (const snsRec of snsEvent.Records) { | |
try { | |
for (const s3Rec of JSON.parse(snsRec.Sns.Message).Records || []) { | |
if (s3Rec.eventSource !== 'aws:s3') continue | |
s3Event.Records.push(s3Rec) | |
} | |
} catch (err) { | |
console.error(`failed to extract S3Event record from SNSEvent record: ${err.message}`) | |
} | |
} | |
return s3Event | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment