Function is succeeding but getting {“message”: “Internal server error”} on API Gateway responses with serverless framework 1.17
Need some help regarding how to debug this further. I have read the other posts that are similar in the forum but haven’t been able to resolve the issue yet. I using serverless framework 1.17.0. When I send a http PUT to the API gateway endpoint I am receiving the following:
response header:
content-length →36
content-type →application/json
date →Sat, 12 Aug 2017 22:21:15 GMT
status →502
via →1.1 12d553da488f4b888f83cd96bab2823b.cloudfront.net (CloudFront)
x-amz-cf-id →w6nuC215apoGNNgD3VfErtxiGsKBUVUJ0meGBI9Okj5nzf2f3qvnxQ==
x-amzn-requestid →8d01894b-7fac-11e7-a18a-b1a7078f6dae
x-cache →Error from cloudfront
response body:
{
"message": "Internal server error"
}
This is the response as contained in the sls logs:
I have read the serverless document regarding the setup of API Gateway events and tried to setup the statusCode, headers and body as shown in that document. What am I missing?
Can you include your handler code? At least he part(s) that determine the response object.
Usually, I get this error when I forget to JSON.stringify() the body payload for the lambda-proxy integration but it looks like you’re doing that, so it must be something else in the returned object that’s doing it. You can tell it’s an issue with the payload, because the error is happening when API Gateway is attempting to “render” the response - everything is fine in your code, but getting 500s on the client.
In the code you’ve shared you’ve got a header “Access-Control-Allow-*” that you didn’t have in your original snippet. Is that (the wildcard in the header name) allowed? I haven’t seen it before.
I must be missing something in my configuration. I have another simple function that queries data from a dynamoDB table. The query is successful and I can see the results in the logs but the client still gets the {“message”: “Internal server error”}
okay, I have to be missing something obvious. I simplified even further using a basic ‘Hello World’ example. Testing using sls invoke -f hello works as expected. However when I use postman to execute a simple GET request the client still gets the status 502 Bad Gateway with {“message”: “Internal server error”} I have included below both the function definition as well as the handler.