Mapping Lambda output to API Gateway header

孤者浪人 提交于 2019-12-03 04:21:03

问题


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.


回答1:


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.




回答2:


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




回答3:


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.




回答4:


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).



来源:https://stackoverflow.com/questions/31723829/mapping-lambda-output-to-api-gateway-header

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