【发布时间】:2018-03-16 00:02:56
【问题描述】:
我正在尝试使用 aws cli 设置一些自定义 API 网关响应。这是我正在使用的命令(仅相关参数):
aws apigateway put-gateway-response --response-parameters method.response.header.Access-Control-Allow-Origin='"'"'*'"'"'
完整的命令是:
aws apigateway put-gateway-response --rest-api-id w1s3nc4dxd --response-type UNAUTHORIZED --status-code 401 --response-parameters method.response.header.Access-Control-Allow-Origin=' "'"'*'"'"' --response-templates '{ "application/json": "{\"errorcode\":401,\"message\":$context.error.messageString}" }' - -region eu-west-1
它失败了:
调用 PutGatewayResponse 操作时发生错误 (BadRequestException):指定的映射表达式无效:验证结果:警告:[],错误:[指定的映射表达式无效:method.response.header.Access-Control-Allow-Origin]
如果在没有该参数的情况下执行,一切正常。我也试过json格式,结果一样。
--response-parameters '{"method.response.header.Access-Control-Allow-Origin":"'"'*'"'"}'
有什么见解吗?提前致谢。
--- 编辑
只是为了进一步澄清。所有类型的响应参数都会失败,这不仅涉及 Access-Control-Allow-Origin 标头。
【问题讨论】:
-
您是否启用了 CORS?
-
好吧,我不太确定为什么 CORS 与此相关。我的一些端点启用了 CORS,而另一些则没有。只是试图为 API 网关响应设置一个标头。为了更清楚,无论响应参数是什么,它都会失败。
标签: amazon-web-services aws-api-gateway