将Lambda输出映射到API网关标头 [英] Mapping Lambda output to API Gateway header

查看:111
本文介绍了将Lambda输出映射到API网关标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Lambda函数的JSON输出映射到API Gateway调用的标头.作为此处的示例,我们可以考虑重定向方案.因此,我想在我的API网关调用的响应中添加Location标头.

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.

Lambda函数的JSON输出:

JSON output from Lambda function:

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

在方法响应"->响应头"中,可以将Location头添加到所需的HTTP状态代码中.

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

然后在集成响应"->标题映射"中,将Location标题的映射添加为某物.

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?

注意:我已经尝试过integration.response.header.Location,或者使用了映射模板",但到目前为止还没有运气.

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

目前有可能无法实现( https://forums.aws. amazon.com/thread.jspa?messageID=651482 ),但是由于API网关/Lambda的发展如此之快,所以我还是要问.

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.

推荐答案

在今天(2015年9月25日)的AWS开发人员论坛中,这还不可能,但将来可能会发生:

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

API网关当前不支持从集成响应主体到响应标头的映射,但是我们希望将来增加对此的支持.

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.

此处发布论坛

编辑2015年12月:该功能是根据AWS员工在上面链接的帖子中的帖子所添加的.感谢彼得·福克斯指出这一点.

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.

这篇关于将Lambda输出映射到API网关标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆