Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda function through API gateway fails due to Malformed Lambda proxy response

for some reason my AWS lambda returns a 502 error no matter how i change my response.

Sun Mar 25 03:39:12 UTC 2018 : Endpoint response body before transformations: {"status":200,"body":"{\"Items\":[],\"Count\":0,\"ScannedCount\":1}","isBase64Encoded":false,"headers":{"content-type":"application/json"}}

I have made sure to stringify my body and add the status, headers, and isBase64Encodeded properties. I have tried varying the headers and making them empty as well.

Why do i get this error?

here is the lambda code:

    var response = {
        status : 200,
        body : JSON.stringify(data),
        isBase64Encoded : false,
        headers : {"content-type" : "application/json"}
    }

    console.log(response)

    callback(null, response);
like image 240
user3314863 Avatar asked Nov 01 '25 07:11

user3314863


1 Answers

API Gateway expects statusCode, not status.

https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format

like image 73
Michael - sqlbot Avatar answered Nov 02 '25 21:11

Michael - sqlbot



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!