简体   繁体   English

AWS获取用于云形成的API网关URL

[英]AWS Get API Gateway URL for Use in Cloud Formation

I'm looking to use CloudFormation to build my AWS stack which includes an API Gateway with Usage Plans. 我希望使用CloudFormation构建我的AWS栈,其中包括一个带有使用计划的API网关。 I'd like to specify my usage plans in my main CloudFormation template, rather than having to add them as a change-set after the initial stack create. 我想在我的主CloudFormation模板中指定我的使用计划,而不是在初始堆栈创建后将它们添加为更改集。 The problem is that the stack fails to create when I include the usage plan because (I think) the API Gateway is not finished deploying when it tries to create the usage plans since I get an error saying that the stage "prod" does not exist. 问题是当我包含使用计划时堆栈无法创建,因为(我认为)API Gateway在尝试创建使用计划时没有完成部署,因为我收到一条错误,指出阶段“prod”不存在。 My CloudFormation template (extract) looks like this: 我的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

I thought adding DependsOn: Api to the usage plan definition would work but it doesn't so I'm out of ideas? 我认为将DependsOn: Api添加到使用计划定义中会起作用,但事实并非如此我没有想法?

It seems like my DependsOn statement should be on the ApiDeployment which I can see in the stack create events is still in progress when it tries to create the usage plan 似乎我的DependsOn语句应该在ApiDeployment上,我可以在堆栈中看到创建事件在尝试创建使用计划时仍在进行中

The only way I've found that can do this is by setting the DependsOn property of the Usage plan to the logical Api Stage name which is {LogicalApiName}{StageName}Stage for example in my case: 我发现可以做到这一点的唯一方法是将Usage计划的DependsOn属性设置为逻辑Api Stage名称{LogicalApiName} {StageName} Stage例如在我的情况下:

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

I don't like this as it relies on the logical stage naming convention which I don't believe is officially documented in the AWS CloudFromation docs, however it appears to be the only reliable option 我不喜欢这个,因为它依赖于我认为在AWS CloudFromation文档中没有正式记录的逻辑阶段命名约定,但它似乎是唯一可靠的选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 AWS Cloudformer 为现有 API 网关创建云形成模板? - How can I use AWS Cloudformer to create a cloud formation template for an existing API Gateway? 如何将 AWS 无服务器应用程序项目更改为仅部署为 lambda 功能? (没有API网关和云编队) - How to change an AWS Serverless application project to just deploy as lambda functions? (No API gateway and cloud formation) AWS Cloud Formation WordPress URL 超时 - AWS Cloud Formation WordPress URL Times Out 如何在AWS API Gateway中使用分段URL? - How use segmented URL in AWS API Gateway? AWS:Cloud Formation:是否可以使用多个“DependsOn”? - AWS: Cloud Formation: Is it possible to use multiple “DependsOn”? AWS云形成模板 - AWS Cloud Formation templates AWS云形成的自动化 - Automation For AWS Cloud formation 如何让 AWS API 网关在 AWS Lambda function 中调用 URL? - How to get AWS API Gateway invoke URL in an AWS Lambda function? 使用AWS Cloud Formation重复配置AWS环境有多普遍? - How common is it to use AWS Cloud Formation for repeated provisioning of AWS environments? Lambda API 结果作为在 Cloud Formation 中创建 AWS 资源的条件 - Lambda API result as a condition to create AWS resource in Cloud Formation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM