【问题标题】:CloudFormation stack resource dependency issues: API Gateway Deployment + UsagePlanCloudFormation 堆栈资源依赖问题:API Gateway Deployment + UsagePlan
【发布时间】: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


【解决方案1】:

UsagePlan 可以跨多个 API 重复使用。因此,理想情况下,我们建议您为每个 API 使用不同的 CloudFormation 堆栈,并为 UsagePlans 使用不同的 CloudFormation 堆栈。这样,您可以在不删除 UsagePlan 且不涉及此依赖性问题的情况下删除 API。

【讨论】:

  • 我明白你在说什么,但认为这有点问题。即使我要为使用计划创建不同的模板,我也需要在使用 API 部署之后创建该堆栈。然后我需要以相反的顺序删除它们。这使得我无法自动化该过程。一个简单的解决方法是能够在 Deployment 中指定 UsagePlan,而不是在 UsagePlan 中指定 Deployment(如果 AWS 有人在听的话!)。
猜你喜欢
  • 2020-08-30
  • 2020-10-05
  • 2020-01-17
  • 1970-01-01
  • 2021-01-19
  • 2020-11-09
  • 2016-03-10
  • 2019-05-09
  • 1970-01-01
相关资源
最近更新 更多