gpt4 book ai didi

json - AWS Cloudformation APIGateway 尝试设置静态 header 值时遇到不受支持的属性 IntegrationResponses

转载 作者:行者123 更新时间:2023-12-03 07:17:30 25 4
gpt4 key购买 nike

我正在尝试使用 Cloudformation 在 AWS APIGateway 的方法执行上设置 header 映射。

这是我希望的最终状态: enter image description here

这是我尝试使用的 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

文档 here说:

Static value 'STATIC_VALUE'. The STATIC_VALUE is a string literal and must be enclosed within a pair of single quotes.

我已经尝试了所有我能想到的逃脱组合,但都无济于事。

最佳答案

您给定的模板存在两个问题。

第一个是,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
}]
}
}

关于json - AWS Cloudformation APIGateway 尝试设置静态 header 值时遇到不受支持的属性 IntegrationResponses,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50863975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com