Amazon API Gateway : response body is not transformed when the API is called via Postman?

浪子不回头ぞ 提交于 2019-11-30 18:10:41

问题


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.


回答1:


Before the changes are externally visible, you need to Deploy the API !




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!