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....
Asked
Active
Viewed 7,749 times
3
-
5Possible 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 Answers
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
-
1If in some case I dont want to pass any data to 2nd function but want to receive data from it, is it possible? – ABCD May 16 '18 at 13:56
-
-
-
1in Payload just pass an empty string and you will get data returned by second function in data object – siraj pathan May 16 '18 at 13:59
-
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..... – ABCD May 17 '18 at 07:01
-