Can you publish a message to an SNS topic using an AWS Lambda function backed by node.js?
First, you need to grant your Lambda IAM role permissions to publish to your SNS topic using proper IAM policy.
{
"Action" : [
"sns:Publish",
"sns:Subscribe"
],
"Effect" : "Allow",
"Resource" : [
{ "Ref" : "" }
]
}
Then you can use following code to SNS publish to your SNS topic from your other Lambda or Node.js code.
var message = {};
var sns = new AWS.SNS();
sns.publish({
TopicArn: "",
Message: JSON.stringify(message)
}, function(err, data) {
if(err) {
console.error('error publishing to SNS');
context.fail(err);
} else {
console.info('message published to SNS');
context.succeed(null, data);
}
});