无法检查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 (将#修改为@)