首页 文章

CloudFormation堆栈资源依赖性问题:API Gateway Deployment UsagePlan

提问于
浏览
3

我正在使用CloudFormation模板来部署API网关资源,并且遇到部署(AWS :: ApiGateway :: Deployment)和UsagePlan资源的问题 . 这是一种鸡/蛋的情况 .

在UsagePlan中,我指定了ApiStage的配置,这意味着我需要先创建部署资源 . 但是,当我尝试删除堆栈时,UsagePlan出现故障,因为相应的阶段仍然连接到UsagePlan .

我有一个UsePlan的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"
  ]
}

1 回答

  • 3

    UsagePlan可以在多个API中重用 . 因此,理想情况下,我们建议您为每个API使用不同的CloudFormation堆栈,并为UsagePlans使用不同的CloudFormation堆栈 . 这样,您可以在不删除UsagePlan的情况下删除API,而不会遇到此依赖性问题 .

相关问题