When executing a testvia the AWS API Gateway console, I see that the output response from the Lambda function is correctly transformed:
{
"type" : "",
"message" : "",
"request-id" : ""
}
See logs below:
Tue Sep 06 14:46:06 UTC 2016 : Endpoint request body after transformations: {}
Tue Sep 06 14:46:06 UTC 2016 : Endpoint response body before transformations: {"errorMessage":"501stef"}
Tue Sep 06 14:46:06 UTC 2016 : Endpoint response headers: {x-amzn-Remapped-Content-Length=0, x-amzn-RequestId=a4540f42-7440-11e6-90ce-214b29fcde38, Connection=keep-alive, Content-Length=26, Date=Tue, 06 Sep 2016 14:46:06 GMT, Content-Type=application/json}
Tue Sep 06 14:46:06 UTC 2016 : Method response body after transformations: {
"type" : "",
"message" : "",
"request-id" : ""
}
Tue Sep 06 14:46:06 UTC 2016 : Method response headers: {Content-Type=application/json}
Tue Sep 06 14:46:06 UTC 2016 : Successfully completed execution
Tue Sep 06 14:46:06 UTC 2016 : Method completed with status: 501
However when calling the API via Postman with headers:
Content-Type : application/json
Accept : application/json
No output transformation is happening, and the output JSON message is just:
{
"errorMessage": "501stef"
}
Partly related to Amazon APi gateway fails to generate transformed request but this one talks about the Request.
The difference between Test Invoke on API Gateway Console and actual Invoke with API Gateway is the test invoke is always assuming the content-type is "application/json" and accept "application/json". You might want to pass "application/json" with the header accept when you invoke via Postman.
来源:https://stackoverflow.com/questions/39352240/amazon-api-gateway-response-body-is-not-transformed-when-the-api-is-called-via


