0

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);           
    }
  });


devban
  • 1
  • 1
  • There is a working example here https://stackoverflow.com/a/50938790/2188922 – Ersoy Jun 10 '20 at 18:28
  • Thanks. I saw a few similar examples, that all use InvokationType as "Request Response". In my case, I want to fire the second lambda and forget about it. The example in that link, waits for the promise from the second lambda. Is there any way I can avoid that? – devban Jun 10 '20 at 18:34
  • Have you inspected cloudwatch logs for the second function? Do you have DLQ setup for the second function as well? – Marcin Jun 10 '20 at 21:31
  • I can see in cloudwatch metrics and log that the first function is being invoked. When I manually invoke the second function, it shows up in both cloudwatch metrics and log groups. However, there is nothing that happens when I try to trigger the second function from the first. – devban Jun 11 '20 at 17:04

0 Answers0