I'm working on a CloudFormation template to deploy API Gateway resources and having issues with the Deployment (AWS::ApiGateway::Deployment) and UsagePlan resources. It's sort of a chicken/egg situation.
In the UsagePlan I specify the ApiStage's configuration, which means that I need to have the Deployment resource created first. However, when I try to delete the stack the UsagePlan has a failure because the corresponding stage is still connected to the UsagePlan.
I have a DependsOn statement for the UsagePlan (UsagePlan depends on the deployment). This allows the stack to create without issue. But because of this DependsOn statement, it forces the UsagePlan to delete first on the delete action. This causes the error.
See pertinent code excerpt below.
Anyone have a solution for this issue? I can't be the first one to stumble on this!
Thanks!
"UppRestApiDeployment": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"Description": "Upp Rest API Deployment",
"RestApiId": {
"Ref": "UppRestApi"
},
"StageName": {
"Ref": "StackIdentifier"
},
"StageDescription": {
"CacheClusterEnabled": false,
"CacheClusterSize": "0.5",
"CacheDataEncrypted": false,
"CacheTtlInSeconds": 10,
"CachingEnabled": false,
"DataTraceEnabled": false,
"LoggingLevel": "ERROR",
"MetricsEnabled": true,
"StageName": {
"Ref": "StackIdentifier"
},
"Description": {
"Fn::Sub": "${StackIdentifier} Stage"
},
"ThrottlingBurstLimit": 2000,
"ThrottlingRateLimit": 1000,
"Variables": {
"lambdaAlias": {
"Ref": "StackIdentifier"
}
}
}
}
},
"UppApiUsagePlan": {
"Type": "AWS::ApiGateway::UsagePlan",
"Properties": {
"ApiStages": [
{
"ApiId": {
"Ref": "UppRestApi"
},
"Stage": {
"Ref": "StackIdentifier"
}
}
],
"Description": "Upp Rest API Usage Plan to Prevent Overage Charges",
"Quota": {
"Limit": 5000,
"Period": "MONTH"
},
"Throttle": {
"BurstLimit": 200,
"RateLimit": 100
},
"UsagePlanName": {
"Fn::Sub": "${StackIdentifier}_UppApiUsagePlan"
}
},
"DependsOn": [
"UppRestApiDeployment"
]
}