Reputation: 339
I am trying to set my Header Mappings on the Method Execution of an AWS APIGateway using Cloudformation.
Here is what I want my end state to be:
Here is the Cloudformation JSON Template snippet I am trying to use:
"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
}
]
}
},
When I run the template I get the following error:
14:23:06 UTC-0400 CREATE_FAILED AWS::ApiGateway::Method AlertDetailMock Encountered unsupported property IntegrationResponses
The documentation here says:
Static value 'STATIC_VALUE'. The STATIC_VALUE is a string literal and must be enclosed within a pair of single quotes.
I have tried every combination of escape that I could think of to no avail.
Upvotes: 1
Views: 2366
Reputation: 14039
There are two issues with your given template.
The first one is, that the IntegrationResponses
element needs to be inside the Integration
element.
The second issue is related to the escaping, you actually do not need to escape single quotes in JSON. So just placing the value inside is fine.
"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
}]
}
}
Upvotes: 7