1

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

2 Answers 2

3

Couple things to check:

Sign up to request clarification or add additional context in comments.

Comments

1

Also check your CloudWatch logs for the Lambda function, if it is being triggered you'll have a log entry. This is also your way of producing a debug trace from your function and will show any errors.

I'm developing in Java, so Serverless is no help to me, but as a Node developer you might also find this set of tools useful. https://github.com/serverless/serverless

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.