Skip to content

Instantly share code, notes, and snippets.

@RishiRajSahu
Created February 4, 2020 05:12
Show Gist options
  • Save RishiRajSahu/9cad20b2e87d0da11225542204dfc0c1 to your computer and use it in GitHub Desktop.
Save RishiRajSahu/9cad20b2e87d0da11225542204dfc0c1 to your computer and use it in GitHub Desktop.
PublishLambda.js
const HttpStatus = require('http-status-codes')
const { getSnsClient, getArnForTopic } = require('../common/helper')
module.exports.handler = async event => {
console.log('Receiver Event : ', event)
try {
const response = await publishSnsTopic(event.body)
console.log('Response : ', response)
return {
statusCode: HttpStatus.OK
}
} catch (err) {
console.log('err : ', err)
return {
statusCode: 500,
body: JSON.stringify({
message: 'Couldn\'t published the message due to an internal error.'
})
}
}
}
async function publishSnsTopic (data) {
const params = {
Message: JSON.stringify(data),
TopicArn: getArnForTopic(process.env.SNS_LAMBDA_EVENTS_TOPIC)
}
const snsClient = getSnsClient()
return snsClient.publish(params).promise()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment