gpt4 book ai didi

aws-cloudformation - 如何在 Cloud Formation 模板中使列表项成为条件?

转载 作者:行者123 更新时间:2023-12-04 00:46:18 26 4
gpt4 key购买 nike

我有以下创建代码管道的云形成模板。该管道分为三个阶段:

  Stages:
-
Name: "Source"
Actions:
-
Name: "Source"
ActionTypeId:
Category: "Source"
Owner: "ThirdParty"
Version: "1"
Provider: "GitHub"
OutputArtifacts:
- Name: "MyApp"
Configuration:
Owner: !Ref GithubOwner
Repo: !Ref GithubRepo
PollForSourceChanges: "true"
Branch: !Ref GithubBranch
OAuthToken: !Ref GithubTokenParameter
RunOrder: 1
-
Name: "Run-Unit-Tests"
Actions:
-
InputArtifacts:
- Name: "MyApp"
Name: "UnitTests"
ActionTypeId:
Category: "Test"
Owner: "AWS"
Version: "1"
Provider: "CodeBuild"
OutputArtifacts:
- Name: "MyTests"
Configuration:
ProjectName: !Ref CodeBuildName
RunOrder: 1
-
Name: "Deploy-Staging"
Actions:
-
InputArtifacts:
- Name: "MyApp"
Name: "Deploy-Staging"
ActionTypeId:
Category: "Deploy"
Owner: "AWS"
Version: "1"
Provider: "ElasticBeanstalk"
Configuration:
ApplicationName: !Ref BeanstalkApplicationName
EnvironmentName: !Ref BeanstalkEnvironmentStaging
RunOrder: 1

我还有一个条件:

IncludeStagingEnv: !Equals [Staging, !Ref CodePipelineEnvironment]

当条件为 false 时,我想省略代码管道阶段列表中的第 3 项。

我尝试将 !If 与 AWS::NoValue 一起使用,但 NoValue 不是有效的列表项:

Stages:
- !IF
- IncludeStagingEnv
- Name: "Deploy-Staging"
Actions:
-
InputArtifacts:
- Name: "MyApp"
Name: "Deploy-Staging"
ActionTypeId:
Category: "Deploy"
Owner: "AWS"
Version: "1"
Provider: "ElasticBeanstalk"
Configuration:
ApplicationName: !Ref BeanstalkApplicationName
EnvironmentName: !Ref BeanstalkEnvironmentStaging
RunOrder: 1
- AWS::NoValue

IncludeStagingEnv==false 时如何省略最后一项?

最佳答案

我的 Cloudfront 发行版模板上也出现同样的问题。

解决方案是将 AWS::NoValue Ref 属性结合使用。

...
LambdaFunctionAssociations:
Fn::If:
- Authentication
- - EventType: "viewer-request"
LambdaFunctionARN: "arn:aws:lambda:us-east-1:..."
- - Ref: "AWS::NoValue"
...

如果这对所有资源都适用,您应该将条件部分更改为:

Stages:
- !If
- IncludeStagingEnv
- - Name: "Deploy-Staging"
Actions:
- InputArtifacts:
...
- - Ref: "AWS::NoValue"

希望这有帮助!

关于aws-cloudformation - 如何在 Cloud Formation 模板中使列表项成为条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45664638/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com