【问题标题】:AWS Get API Gateway URL for Use in Cloud FormationAWS 获取 API Gateway URL 以在 Cloud Formation 中使用
【发布时间】:2017-08-18 02:10:27
【问题描述】:

我希望使用 CloudFormation 来构建我的 AWS 堆栈,其中包括一个带有使用计划的 API 网关。我想在我的主 CloudFormation 模板中指定我的使用计划,而不是在初始堆栈创建后将它们添加为更改集。问题是,当我包含使用计划时,堆栈无法创建,因为(我认为)API Gateway 在尝试创建使用计划时没有完成部署,因为我收到一条错误消息,指出“prod”阶段不存在.我的 CloudFormation 模板(摘录)如下所示:

  Api:
    Properties:
      CacheClusterEnabled: true
      CacheClusterSize: '0.5'
      DefinitionUri: {MYS3URL}
      StageName: prod
    Type: AWS::Serverless::Api
  ApiFreeUsagePlan:
    DependsOn: Api
    Properties:
      ApiStages:
      - ApiId:
          Ref: Api
        Stage: prod
      Description: Free usage plan
      UsagePlanName: Free
    Type: AWS::ApiGateway::UsagePlan

我认为将DependsOn: Api 添加到使用计划定义中会起作用,但它没有,所以我没有想法?

似乎我的 DependsOn 语句应该在 ApiDeployment 上,我可以在堆栈中看到创建事件在尝试创建使用计划时仍在进行中

【问题讨论】:

    标签: amazon-web-services aws-api-gateway amazon-cloudformation


    【解决方案1】:

    我发现可以做到这一点的唯一方法是将使用计划的 DependsOn 属性设置为逻辑 Api 阶段名称,例如在我的例子中是 {LogicalApiName}{StageName}Stage:

    Api:
      Properties:
        CacheClusterEnabled: true
        CacheClusterSize: '0.5'
        DefinitionUri: {MYS3URL}
        StageName: prod
      Type: AWS::Serverless::Api
    ApiFreeUsagePlan:
      DependsOn: ApiprodStage
    

    我不喜欢这个,因为它依赖于逻辑阶段命名约定,我认为 AWS CloudFromation 文档中没有正式记录,但它似乎是唯一可靠的选择

    【讨论】:

      猜你喜欢
      • 2015-01-03
      • 2018-08-28
      • 2021-06-29
      • 2019-10-17
      • 2018-03-05
      • 1970-01-01
      • 1970-01-01
      • 2016-12-10
      • 2019-03-17
      相关资源
      最近更新 更多