Skip to content

Instantly share code, notes, and snippets.

@yossale
Last active May 12, 2020 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yossale/9fbd5cfe02de2f7dab20841901b452d7 to your computer and use it in GitHub Desktop.
Save yossale/9fbd5cfe02de2f7dab20841901b452d7 to your computer and use it in GitHub Desktop.
const response = require('cfn-response-promise')
const util = require('util')
async function replyToResourceRequest(event, context) {
return await response.send(event, context, response.SUCCESS, {});
}
async function saveUserDetailsToDb(AccountId, RoleArn, ExternalID) {
console.log(`Persisting the user info to the database ${AccountId}, ${RoleArn}, ${ExternalID}`)
// do some db things...
}
module.exports.handler = async (event, context) => {
console.log(`Got SNS message: ${util.inspect(event, { depth: 10 })}`)
const snsMessage = event.Records[0].Sns
const resourceEvent = JSON.parse(snsMessage.Message)
let AccountID, RoleArn, ExternalID
({ AccountID, RoleArn, ExternalID } = resourceEvent.ResourceProperties)
await saveUserDetailsToDb(AccountID, RoleArn, ExternalID)
await replyToResourceRequest(resourceEvent, context)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment