Stef Heyenrath
Stef Heyenrath

Reputation: 9830

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

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

enter image description here

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.

Upvotes: 6

Views: 12889

Answers (2)

Stef Heyenrath
Stef Heyenrath

Reputation: 9830

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

enter image description here **enter image description here**

Upvotes: 11

Ka Hou Ieong
Ka Hou Ieong

Reputation: 6525

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.

Upvotes: 1

Related Questions