Currently
I have a lambdaX that invokes another lambdaY.
Lambda X:
"use strict";
const AWS = require('aws-sdk');
AWS.config.region = 'ap-southeast-2';
var lambda = new AWS.Lambda();
exports.handler = async (event) => {
//the final return
var dataToSave = []
//data to be added to array
let returnLoad;
var params = {
FunctionName: 'lambdaY', // the lambda function we are going to invoke
InvocationType: 'RequestResponse',
LogType: 'Tail', //Set to Tail to include the execution log in the response.
};
try {
await lambda.invoke(params, function(err, data) {
if (err) {
console.log("Error");
console.log(err, err.stack);
} else {
console.log("Success");
console.log(data);
returnLoad = data.Payload;
}
}).promise();
dataToSave.push(returnLoad);
} catch (err) {
console.log('some error occurred...');
}
const response = {
statusCode: 200,
body: JSON.stringify(dataToSave)
};
return response;
}
Lambda Y:
exports.handler = async (event) => {
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
Problem
For some reason lambdaY invokes 2+ times whenever I invoke lambdaX. Note, lambdaX gets the correct response back, but I want to avoid unnecessarily invoking lambdaY multiple times.
What do I need to change in my code? (or lambda configuration)
Logs:
Note: 2 logs of lambdaY being invoked at exactly the same time.
Note: LambdaX results are healthy and as expected. There isn't a duplicate log.

