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.
To pass custom headers from an API Gateway API to a Lambda function, use a body mapping template. The API sends the updated API request to a Lambda function to process the headers. Then, the Lambda function returns one or more header values from the original API request.
For a Lambda authorizer of the REQUEST type, API Gateway passes request parameters to the authorizer Lambda function as part of the event object. The request parameters include headers, path parameters, query string parameters, stage variables, and some of request context variables.
And yes, you can call this API (Lambda proxy) as any Rest API.
As of today (January 2016), it works by simply specifying integration.response.body.Location
in your case.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With