Reputation: 2035
Based on what I've seen posted here and elsewhere it seems that a few days ago adding custom response headers is now possible. Unfortunately, I can't seem to find any examples.
I'm using lambda (python) to power the API and I can't seem to get response headers mapped.
Can anyone please provide 2 basic examples: (1) How do map into a custom header like "X-API-VER: xyz" where xyz comes from lambda's response (2) How to map a Set-Cookie header with the cookie string from lambda?
I've tried this response in lambda:
{
"X-API-VER": "xyz",
}
Then as the response mapping:
{
"method.response.header.X-API-VER" : "integration.response.header.X-API-VER",
}
But that just changes the response to the same thing:
{
"method.response.header.X-API-VER" : "integration.response.header.X-API-VER",
}
I can't seem to figure out how to extract the data from the lambda response to set the header, while outputting the rest of the lambda response as normal passthrough.
If it matters, we're using the web interface for API Gateway.
Anyone figure this out yet?
Upvotes: 2
Views: 424
Reputation: 2035
Figured it out! Looks like I was trying to do this in Response Mapping when in fact I should have been doing the Header mapping as outlined here:
https://stackoverflow.com/a/33676951/545447
Upvotes: 1
Reputation: 2066
Try "body" instead of "header" in the integration response mapping expression:
integration.response.body.X-API-VER
Refer to this document for mapping integration responses to API Gateway method responses: https://docs.aws.amazon.com/apigateway/latest/developerguide/request-response-data-mappings.html#mapping-response-parameters
Upvotes: 2