Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AWS Lambda function to publish to SNS topic
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!');
});
};
@xavrr

This comment has been minimized.

Copy link

@xavrr xavrr commented Mar 19, 2016

nice thanks!

@ravindranathakila

This comment has been minimized.

Copy link

@ravindranathakila ravindranathakila commented May 10, 2016

Could
var sns = new AWS.SNS();
be a field variable?

@kyletolle

This comment has been minimized.

Copy link

@kyletolle kyletolle commented May 22, 2016

Thanks! This was very helpful to help me send a text message from a Lambda function.

@nickheppleston

This comment has been minimized.

Copy link

@nickheppleston nickheppleston commented May 25, 2016

Any thoughts on how we can externalize the TOPIC_ARN property?

@IJNtap

This comment has been minimized.

Copy link

@IJNtap IJNtap commented Aug 22, 2016

For some reason, as soon as I tested that code, I got more than 800 push messages on every device and it doesn't stop. What can I do to fix it and to stop retrieving anymore push messages?

@sjvkishore

This comment has been minimized.

Copy link

@sjvkishore sjvkishore commented Apr 10, 2017

I hope you might using the same Lambda function for both write and subscribe to a topic, it leads to - endless loop

@yogitado

This comment has been minimized.

Copy link

@yogitado yogitado commented May 22, 2017

Where I can see message published to SNS topic?

@johnelliott

This comment has been minimized.

Copy link

@johnelliott johnelliott commented Jun 7, 2017

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.

@ashish-nodejs

This comment has been minimized.

Copy link

@ashish-nodejs ashish-nodejs commented Oct 25, 2018

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

@mechazod

This comment has been minimized.

Copy link

@mechazod mechazod commented Apr 28, 2020

It works with me but I didn't add the TopicARN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.