18
votes

I'm trying to map the JSON output from a Lambda function to the header of an API Gateway call. As an example here, we can consider a redirect scenario. So I'd like to add a Location header to the response from my API Gateway call.

JSON output from Lambda function:

{
    Location: 'http://google.com'
}

In "Method Response"->"Response Headers" I can add the Location header to the desired HTTP status code.

Then in "Integration Response"->"Header Mappings" I can add the mapping for the Location header to be something.

Now my question is what should this something be?

Note: I've tried integration.response.header.Location, or using "Mapping Templates" but no luck so far.

There's a chance that it might not be possible at the moment (https://forums.aws.amazon.com/thread.jspa?messageID=651482), but since API Gateway/Lambda are evolving so quickly at the moment I'll ask anyway.

5
Map the output from your Lambda function to the headers and output model of the 200 method response. This statement from the Integration response screen in API Gateway makes it look like it should be possible. But unable to find out how.user3526

5 Answers

3
votes

From the AWS developer forums today (25 September 2015) this isn't possible yet, but may be coming in the future:

API Gateway does not currently support mapping from the integration response body to the response headers, but we are looking to add support for this in the future.

Forum post here

Edit December 2015: Feature as been added according to a post by an AWS employee in the thread linked above. Thanks to Peter Fox for pointing that out.

10
votes

As of today (January 2016), it works by simply specifying integration.response.body.Location in your case.

5
votes

Today (12th, November, 2015), I was looking for how to pass the Location header from my backend API to a Location header in integration response.

This configuration worked and I could get Location header from backend api:

enter image description here

Looks like the solution proposed by Tobias is possible currently. However, the Location header points to the backend API and this is not what we want. I'll try to find a solution for this and post it here.

1
votes

Actually, it seems you can access to all the headers provided by the original response (if it contains a Content-type, then you can type : integration.response.header.Content-type). However, I have not find out any way to add a new header (except statically).

0
votes

I know it has been a while since this was asked but you can now set:

integration.response.header.Location (note Uppercase L in Location) in Mapping value if you are setting it in response headers.

Example