0 votes
1 view
in AWS by (19.2k points)

I am going through a basic AWS on how to create a lambda function:


In this example we are creating an image re-sizing service, one way to trigger it is to listen for some image to be pushed to an S3 bucket and then lambda function will be executed.

But I am trying to understand how to invoke this Lambda function from my nodejs app when the user sends an image to my node server, I send this image to aws lambda via REST API to be re-sized and then receive the new image location as a response.

Is there any kind of example I can follow? I am more interested in the actual invocation part since I already have my lambda service up and running.


1 Answer

0 votes
by (44.6k points)

Using AWS Javascript SDK, you can invoke Lambda directly because of the node.js server (https://www.npmjs.com/package/aws-sdk).

To invoke from your server:

var AWS = require('aws-sdk');

// you shouldn't hardcode your keys in production! See http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html

AWS.config.update({accessKeyId: 'akid', secretAccessKey: 'secret'});

var lambda = new AWS.Lambda();

var params = {

  FunctionName: 'myImageProcessingLambdaFn', /* required */



lambda.invoke(params, function(err, data) {

  if (err) console.log(err, err.stack); // an error occurred

  else     console.log(data);           // successful response


AWS SDK documentation is here: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html

Welcome to Intellipaat Community. Get your technical queries answered by top developers !