Skip to content

Instantly share code, notes, and snippets.

@jinman
Created September 29, 2015 01:48
Show Gist options
  • Select an option

  • Save jinman/d9854e0bb3e071331a48 to your computer and use it in GitHub Desktop.

Select an option

Save jinman/d9854e0bb3e071331a48 to your computer and use it in GitHub Desktop.
LambdaToSNS
var aws = require('aws-sdk');
var sns = new aws.SNS();
exports.handler = function(event, context) {
payload1 = new Buffer(event.payload);
console.log(payload1);
var payload2 = payload1 + ' -- processed by Lambda';
console.log(payload2);
var params = {
Message: payload2,
Subject: 'Message from your IoT Device',
TopicArn: 'arn:aws:sns:us-east-1:395547068926:lambdatosns' //You will have create a topic
};
sns.publish(params, function(err, data) {
if (err) {
context.fail('ERROR:Calling SNS from Lambda: ' + err)
} else {
console.log('Great success! JSON: ' + JSON.stringify(data, null, ' '));
context.succeed('SUCCESS');
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment