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....

ABCD
  • 730
  • 1
  • 13
  • 31
  • 5
    Possible duplicate of [Can an AWS Lambda function call another](https://stackoverflow.com/questions/31714788/can-an-aws-lambda-function-call-another) – Mark May 16 '18 at 13:53

1 Answers1

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

Dimitar Tsonev
  • 3,711
  • 5
  • 40
  • 70
siraj pathan
  • 1,455
  • 1
  • 14
  • 31