简体   繁体   English

AWS API Gateway:模拟集成响应动态标头映射值

[英]AWS API Gateway:Mock integration response dynamic header mapping values

Is it possible to use velocity to dynamically change the header mapping values based on request headers or integration request body mapping templates? 是否可以使用Velocity根据请求标头或集成请求正文映射模板动态更改标头映射值?

To be more specific, as mentioned in the W3C CORS spec Access-Control-Allow-Origin origin-list-or-null , I would like to implement the CORS Access-Control-Allow-Origin header to return the origin host value only if its a match, otherwise return null. 更具体地说,正如W3C CORS规范中提到的Access-Control-Allow-Origin origin-list-or-null一样 ,我想实现CORS Access-Control-Allow-Origin标头仅在以下情况下返回原始主机值:其匹配项,否则返回null。 I know this can be achieved through a lambda function, but lambda introduces additional overhead and costs. 我知道可以通过lambda函数来实现,但是lambda会带来额外的开销和成本。 Just wanted to know whether it is possible to use any velocity template mechanisms in the integration header mappings to achieve this. 只是想知道是否有可能在积分头映射中使用任何速度模板机制来实现这一目标。

You can use the Enable CORS option from Actions for a api gateway resource to do this. 您可以将Actions中的Enable CORS选项用于api网关资源来执行此操作。 It will create a mock request to handle this. 它将创建一个模拟请求来处理此问题。 Only thing instead of the '*' wildcard for the 'Access-Control-Allow-Origin', you have to mention the domain name. 唯一要提及的是域名,而不是“ Access-Control-Allow-Origin”的“ *”通配符。 Check the snapshot below. 检查下面的快照。

在此处输入图片说明

You can get more info from aws documentation 您可以从AWS文档中获取更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM