微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法检查AWS API Gateway VTL模板中的集成响应标头

如何解决无法检查AWS API Gateway VTL模板中的集成响应标头

我正在尝试将AWS API Gateway用作对多个现有内部API资源的HTTP代理,但似乎无法克服我认为简单的问题,即通过网关映射来自内部API的响应。 >

我的内部服务返回一个新创建的资源的位置,该资源的HTTP响应代码201和新资源的Location标头参数,例如https://some.url.com/resource/1233

我有一个简单的VTL模板,希望它可以拦截内部API的响应,剖析Location标头,并使用指向新API网关的已更改的Location标头进行响应:

## Extract the Gateway domain
#set( $gateway = $context.domainName )

## Extract path parameters
#set( $sn = $method.request.path.serial_number )
#set( $an = $method.request.path.account_number )

## Extract the new resource Location from internal API
#set( $loc = $integration.response.header.Location )

## Extract the trailing id of the new resource
#set( $split = $loc.split("/") )
#set( $i = $split.length - 1 )
#set( $id = $split[$i] )

## Build replacement Gateway URL
#set( $gloc = "https://$gateway/info/$sn/$an/$id" )

## Set the final Location header on the response.
#set( $context.responSEOverride.header.Location = $gloc )

忘记Location URL的拆分是否有效(老实说,我还不知道),我什至似乎无法访问VTL模板中内部API的Location标头。 如果我跳过所有拆分并更改最后一行以使其像传递一样,它仍只会添加一个空字符串:

## Extract the new resource Location from internal API
#set( $loc = $integration.response.header.Location )

...

## Set the final Location header on the response.
#set( $context.responSEOverride.header.Location = $loc )

我已经阅读并重新阅读了AWS文档,这些文档都指向能够拦截和检查integration.response对象的 body 内容,但是看起来没有一个标头是可用于VTL脚本进行分析。

我是否误解了VTL映射可用于什么,或者我试图通过HTTP代理API网关请求/响应设置无法实现?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。