Created
September 29, 2015 01:48
-
-
Save jinman/d9854e0bb3e071331a48 to your computer and use it in GitHub Desktop.
LambdaToSNS
This file contains hidden or 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
| 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