【发布时间】:2017-06-26 19:04:06
【问题描述】:
我正在使用 CloudFormation 模板来部署 API Gateway 资源,但在部署 (AWS::ApiGateway::Deployment) 和 UsagePlan 资源方面存在问题。这是一种先有鸡还是先有蛋的情况。
在 UsagePlan 中我指定了 ApiStage 的配置,这意味着我需要首先创建 Deployment 资源。但是,当我尝试删除堆栈时,UsagePlan 失败了,因为相应的阶段仍然连接到 UsagePlan。
我有一个 UsagePlan 的 DependsOn 语句(UsagePlan 取决于部署)。这允许堆栈毫无问题地创建。但是由于这个 DependsOn 语句,它强制 UsagePlan 在删除操作上首先删除。这会导致错误。
请参阅下面的相关代码摘录。
谁有这个问题的解决方案?我不能成为第一个偶然发现这个的人!
谢谢!
"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"
]
}
【问题讨论】:
-
你有点自相矛盾。如果您包含您的 Deployment 和 UsagePlan 资源的代码 sn-p(如果创建为单独的资源,也可以使用 Stage),我相信我们将能够为您解决。
-
感谢您的浏览。我添加了脚本的摘录。
标签: aws-api-gateway amazon-cloudformation