I have a Lambda function, inside which I want to add a small snippet of code, that asynchronously calls another Lambda function (fire and forget).
I have seen a few examples, but they all use 'InvocationType' : RequestResponse. I specifically want this to be fire and forget.
This is the code I am using:
var lambda = new AWS.Lambda();
....
const params = {
'FunctionName': 'Lambda_function_to_be_invoked',
'InvocationType': 'Event',
'Payload': JSON.stringify(usefuldata)
};
var invoke_lambda = lambda.invoke(params,function(err,data){
if(!err)
console.log(data);
else
console.log(err);
})
I have the following policy attached to the IAM role for the first Lambda:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "lambda:InvokeFunction",
"Resource": "arn:aws:lambda:us-east-1:xxxxxx:function:xxxx"
}
]
}
My first lambda doesn't throw a error when running. However,the second lambda is never invoked. I cannot see it in cloutwatch metrics.
I am unsure exactly what I am doing wrong, and the code seems to be straight forward. I would really appreciate any help.
EDIT:
I tried the code in this thread:
and I am still facing the same issue (the second lambda never gets invoked)
Alternative code:
var lambda = new AWS.Lambda();
lambda.invoke({
FunctionName: 'Lambda_function_to_be_invoked',
InvocationType: 'Event',
Payload: JSON.stringify(answers)
}).promise()
I have tried with the following code, and I still am not able to invoke the second function :(
var params = {
FunctionName: "Second_Lambda_Funtion",
InvocationType: 'Event'
};
lambda.invoke(params, function(err, data) {
if (err) {
console.log(err, err.stack);
}
else {
console.log(data);
}
});