Daniel Bojczuk
Daniel Bojczuk

Reputation: 16

Problem with API Gateway and AWS Lambda Function: Malformed Lambda proxy response

I'm trying to make a HelloWorld using a DotNet Core Lambda Function with an API Gateway.

My lambda function is returning

"{\"isBase64Encoded\":false,\"statusCode\":200,\"headers\":{\"Content-Type\":\"application/json\",\"Custom-Header\":\"application/json\"},\"body\":\"{\\u0022message\\u0022:\\u0022ola\\u0022}\"}"

Aws Lambda Function Return Print

But My API Gateway tells me that is a malformed response.

Fri May 22 16:52:12 UTC 2020 : Endpoint response body before transformations: "{\u0022isBase64Encoded\u0022:false,\u0022statusCode\u0022:200,\u0022headers\u0022:{\u0022Content-Type\u0022:\u0022application/json\u0022,\u0022Custom-Header\u0022:\u0022application/json\u0022},\u0022body\u0022:\u0022{\\u0022message\\u0022:\\u0022ola\\u0022}\u0022}"
Fri May 22 16:52:12 UTC 2020 : Execution failed due to configuration error: Malformed Lambda proxy response

Fri May 22 16:52:12 UTC 2020 : Method completed with status: 502

I couldn't find what I'm doing wrong.

Upvotes: -1

Views: 351

Answers (1)

Daniel Bojczuk
Daniel Bojczuk

Reputation: 16

Ok... after some more time researching I found the correct way to do it.

I was tring to create my own JSON string without any success. When I tried to use the APIGatewayProxyResponse object the API Gateway understood the Lambda Function's answer correctly.

Even the answer shown in the AWS Lambda Function test looks different.

AWS Lambda Function return

To use it it's necessary to install the nuget package Amazon.Lambda.APIGatewayEvents

Upvotes: 0

Related Questions