json - AWS Cloudformation APIGateway 在尝试设置静态标头值时遇到不受支持的属性 IntegrationResponses
问题描述
我正在尝试使用 Cloudformation 在 AWS APIGateway 的方法执行上设置我的标头映射。
这是我尝试使用的 Cloudformation JSON 模板片段:
"AlertDetailMock": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"RestApiId": {
"Ref": "RestApi"
},
"ResourceId": {
"Ref": "AlertDetailResource"
},
"HttpMethod": "OPTIONS",
"AuthorizationType": "NONE",
"Integration": {
"Type": "MOCK",
"RequestTemplates": {
"application/json": "{\"statusCode\": 200}"
}
},
"IntegrationResponses": [
{
"ResponseTemplates": {
"application/json": ""
},
"ResponseParameters": {
"method.response.header.Access-Control-Allow-Origin": "\\'*\\'",
"method.response.header.Access-Control-Allow-Methods": "\\'GET,OPTIONS\\'",
"method.response.header.Access-Control-Allow-Headers": "\\'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token\\'"
},
"StatusCode": 200
}
],
"MethodResponses": [
{
"ResponseModels": {
"application/json": {
"Ref": "AlertDetailsModel"
}
},
"ResponseParameters": {
"method.response.header.Access-Control-Allow-Origin": true,
"method.response.header.Access-Control-Allow-Methods": true,
"method.response.header.Access-Control-Allow-Headers": true
},
"StatusCode": 200
}
]
}
},
当我运行模板时,出现以下错误:
14:23:06 UTC-0400 CREATE_FAILED AWS::ApiGateway::Method AlertDetailMock Encountered unsupported property IntegrationResponses
这里的文档说:
静态值“STATIC_VALUE”。STATIC_VALUE 是一个字符串文字,必须用一对单引号括起来。
我尝试了所有我能想到的逃跑组合,但都无济于事。
解决方案
您给定的模板有两个问题。
第一个是,IntegrationResponses
元素需要在Integration
元素内部。
第二个问题与转义有关,您实际上不需要在 JSON 中转义单引号。所以只要把值放在里面就可以了。
"AlertDetailMock": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"RestApiId": {
"Ref": "RestApi"
},
"ResourceId": {
"Fn::GetAtt": ["RestApi", "RootResourceId"]
},
"HttpMethod": "OPTIONS",
"AuthorizationType": "NONE",
"Integration": {
"Type": "MOCK",
"RequestTemplates": {
"application/json": "{\"statusCode\": 200}"
},
"IntegrationResponses": [{
"ResponseTemplates": {
"application/json": ""
},
"ResponseParameters": {
"method.response.header.Access-Control-Allow-Origin": "'*'",
"method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'",
"method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
},
"StatusCode": 200
}]
},
"MethodResponses": [{
"ResponseParameters": {
"method.response.header.Access-Control-Allow-Origin": true,
"method.response.header.Access-Control-Allow-Methods": true,
"method.response.header.Access-Control-Allow-Headers": true
},
"StatusCode": 200
}]
}
}
推荐阅读
- mongodb - 将mongodb数据导入mongo镜像
- java - 在 Android 上运行 shell 命令不会返回任何内容
- node.js - 使用 Nodejs Spawn 启动 Linux 屏幕会话
- mysql - 如何使用node js更新mysql中的多行
- flutter - 如何在颤动中将文本与图像对齐?
- c# - 如何使用 DataRow 列表从基于另一个数据表的数据表中选择值
- julia - Julia - 如何为 FluxML mlp 定义图像数组?
- python - pandas_profiling 主要方法无法正常工作...构造函数有效但方法无效
- ios - 我将 UIGestureReconizer 添加到视图以检测 Touch Down 动作,但是视图上方的按钮将不再起作用
- javascript - 使用 webext-redux 从后台脚本调度操作