I'm trying to unterstand how aws lambda works but i have to admit that i have not totally catch the utility of this aws module. So, from what i know lambda allow to start a script after a event pre-specified ? Ok so i'm trying since a couple of days to build a simple case.
When i upload or delete something from S3, i want my lambda function send me a push notification by Using SNS. Unfortunately, i can't get this work. I don't know how to proceed. I followed the AWS getting started tutorial form lambda, i configured roles and all these stuffs, then i create a node.js function (deployment function) , installed dependencies and zipped all these stuffs then upload this to Aws lambda.
I also configured the event in aws S3, but when i upload or delete a file from S3 i never received any push notification. I just want to know the simplest way to test AWS Lambda because even the amazon sample test lambda function (S3 upload image, resizing and copy to another bucket) doesn't work when i test it.
Here is the code i'm trying to get it works
var async = require('async');
var AWS = require('aws-sdk');
// get reference to S3 client
var s3 = new AWS.S3();
var sns = new AWS.SNS();
exports.handler = function(event, context, callback) {
var params = {
Message: 'STRING_VALUE', /* required */
MessageAttributes: {
someKey: {
DataType: 'raw', /* required */
BinaryValue: new Buffer('...') || 'STRING_VALUE',
StringValue: 'STRING_VALUE'
},
/* anotherKey: ... */
},
MessageStructure: 'Hello from lambda',
Subject: 'STRING_VALUE',
TargetArn: 'XXXXXXX', //my target arn
TopicArn: 'XXXXX' //my topic arn
};
async.waterfall([
sns.publish(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
})
],function(error){
if (error) throw err;
})
};
Any help will be highly appreciated. Thanks