3

I have 2 Lambda function. First fetch data from database and put it in DynamoDB. And Second fetch data from the DynamoDB. I want to execute both lambda function sequentially (i.e.first then second). How could I invoke 2nd Lambda function inside 1st Lambda function? How to pass data to that Lambda function? And how to get response from the 2nd Lambda function? Does anyone know possible way? Please help.... Thank u....

1

1 Answer 1

5

For nodejs you can use lambda.invoke function to execute another lambda

var aws = require("aws-sdk");
var lambda = new aws.Lambda({
  region: "us-west-1",
});

var params = {
  FunctionName: "MyFunction",
  InvocationType: "RequestResponse",
  LogType: "Tail",
  Payload: "<Stringified oject to pass parameters as event>",
};


lambda.invoke(params, function (err, data) {
  if (err) console.log(err, err.stack);
  // an error occurred
  else console.log(data); // successful response
});

for info visit this link: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#invoke-property

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

6 Comments

If in some case I dont want to pass any data to 2nd function but want to receive data from it, is it possible?
Is there any changes required in 2nd function?
No changes required in the second function.
in Payload just pass an empty string and you will get data returned by second function in data object
That worked.... Thank u.... Now 1 last question I am getting desired output in log every time but null in response.. callback(null,cde); // not working & console.log(cde); //working.....
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.