Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

{Status: 202} when running a lambda from code

This is my code in Javascript:

    var params = {
        FunctionName: "theTable",
        InvokeArgs: JSON.stringify({ "name": "KirklandWA" })
    };
    lambda.invokeAsync(params, function (err, data) {
        if (err) console.log(err, err.stack); // an error occurred
        else {
            console.log(data);
        }
    });

This is in Lambda:

exports.handler = async (event, context) => {
    return "theReturnedValue";
};

What is happening is that it is not returning the theReturnedValue, instead returns

{Status: 202} Status: 202

The code in Lambda is getting invoked, I made sure of it at Cloudwatch.

like image 863
AmazingDayToday Avatar asked Sep 02 '26 04:09

AmazingDayToday


1 Answers

You're invoking with invokeAsync which will only return status code as stated in the documentation. Use invoke with InvocationType: "RequestResponse" instead

Reference: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#invoke-property

var lambda = new AWS.Lambda({});
var params = {
  FunctionName: "function_name", 
  InvocationType: "RequestResponse"
};
response = lambda.invoke(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});
like image 186
Van Manh Avatar answered Sep 04 '26 17:09

Van Manh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!