Last active
August 19, 2022 18:09
-
-
Save jeremypruitt/ab70d78b815eae84e037 to your computer and use it in GitHub Desktop.
AWS Lambda function to publish to SNS topic
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
console.log('Loading function'); | |
var AWS = require('aws-sdk'); | |
AWS.config.region = 'us-west-2'; | |
exports.handler = function(event, context) { | |
console.log("\n\nLoading handler\n\n"); | |
var sns = new AWS.SNS(); | |
sns.publish({ | |
Message: 'Test publish to SNS from Lambda', | |
TopicArn: 'TOPIC_ARN' | |
}, function(err, data) { | |
if (err) { | |
console.log(err.stack); | |
return; | |
} | |
console.log('push sent'); | |
console.log(data); | |
context.done(null, 'Function Finished!'); | |
}); | |
}; |
Where I can see message published to SNS topic?
Is using aws-sdk the intended way to publish to SNS? SNS can be a trigger for a function, yet I haven't seen a corresponding way to generate SNS messages.
i want to send push run time of lambda code .Ex i post job and on success i want to send push to predefine deviceIds .
what is the way with SNS plz tell me
It works with me but I didn't add the TopicARN.
Thanks! I adapted this for a project that fires SNS notifications after a file is uploaded to an S3 bucket and triggers a Lambda event. It worked great on the first try after plugging in the TopicARN.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I hope you might using the same Lambda function for both write and subscribe to a topic, it leads to - endless loop