Created
February 4, 2020 05:12
-
-
Save RishiRajSahu/9cad20b2e87d0da11225542204dfc0c1 to your computer and use it in GitHub Desktop.
PublishLambda.js
This file contains 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
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