I have been roaming the forums trying to find a resolution to a “Malformed Lambda proxy response” (status: 502) error message you get when deploying and running an API Gateway Invokation that uses a Lambda-Proxy.
Excuse the post length for sake of being exact.
-
I followed the API Gateway tutorial as described in the serverless docs.
-
I ran into a currently open issue with serverless where lambda triggers do not display in the AWS Console, so I added the API Gateway part from API Gateway itself.
-
Now, my Lambda function works as expected, but the response from API Gateway is that it is malformed (see code snippet below)
Thu Jan 12 20:23:08 UTC 2017 : Endpoint response body before transformations: {“statusCode”:200,“body”:{“tip”:“asdf”}}
Thu Jan 12 20:23:08 UTC 2017 : Endpoint response headers: {x-amzn-Remapped-Content-Length=0, x-amzn-RequestId=…, Connection=keep-alive, Content-Length=78, Date=Thu, 12 Jan 2017 20:23:08 GMT, Content-Type=application/json}
Thu Jan 12 20:23:08 UTC 2017 : Execution failed due to configuration error: Malformed Lambda proxy response
Thu Jan 12 20:23:08 UTC 2017 : Method completed with status: 502 -
I then created a Response Model that would shape the response
{
"$schema": “http://json-schema.org/draft-04/schema#”,
“title”: “Custom Response Schema”,
“type”: “object”,
“properties”: {
“statusCode”: { “type”: “number” },
“body”: {
“type”: “object”,
“properties”: {
“tip”: { “type”: “string” }
}
}
}
}
But, that didn’t seem to help (not does specifying Empty) -
I then reviewed my .yml file and it declared the function as follows
functions:
tips:
handler: handler.getTip
events:- http:
path: tip
method: get
integration: lambda-proxy
- http:
-
And this seemed all fine, so I looked specifically at the IAM Role to see if I had the correct permissions where I had added explicit invoke access to the resource as follows:
{ "Effect": "Allow", "Action": [ "execute-api:Invoke" ], "Resource": [ "arn:aws:execute-api:us-east-1:<AWS_ID>:<APP_ID>/<STAGE>/GET/tip" ] }
-
Which seemed to clear up all permission messages, but I still can’t get past that 502 status of a Malformed Lambda proxy response.
Any ideas what I’ve missed and could I have done all of this via Serverless alone. I am new to Serverless so if I could create the response template, add the IAM permissions, and configure API Gateway to cache the response to 15 minute intervals (on my todo list) ALL within serverless, please help because I’m stumped.