[英]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.