[英]CloudFormation: conditional parameters
Building a CloudFormation stack template, I have a setup constellation where upon instantiation I want to reference either the name of another CloudFormation stack or a non-CloudFormation-managed database as a parameter.构建 CloudFormation 堆栈模板,我有一个设置星座,在实例化时我想引用另一个 CloudFormation 堆栈的名称或非CloudFormation 管理的数据库作为参数。
Is there a way to represent this constellation in my template?有没有办法在我的模板中表示这个星座? Ie "Parameter DatabaseHost
is mandatory if Parameter DatabaseStack
is blank"?即“如果参数DatabaseHost
为空,则必须使用参数DatabaseStack
”?
I'm not aware of a native option in CloudFormation to make one template parameter conditional on a second template parameter.我不知道 CloudFormation 中的本机选项可以使一个模板参数以第二个模板参数为条件。
Possible workarounds might be:可能的解决方法可能是:
Maybe it wasn't possible at the time of the question, but now, you can include conditions on a CloudFormation template.也许在提出问题时不可能,但现在,您可以在 CloudFormation 模板中包含条件。 See docs .请参阅文档。
In this example, I use one value or another depending on the environment:在此示例中,我根据环境使用一个或另一个值:
InfrastructurePipelineStack:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: !Sub "https://<masked>.yml"
Parameters:
ProjectName: !Ref ProjectName
...
LambdaNotifications: !If [isDev, !GetAtt NotificationsStack.Outputs.LambdaNotifications, !Ref LambdaNotifications]
If the environment is Development ("isDev" condition), I use the output of other CloudFormation Stack as the value.如果环境是开发环境(“isDev”条件),我使用其他 CloudFormation Stack 的输出作为值。 If not, I use a provided fixed value (non-CloudFormation value).如果没有,我使用提供的固定值(非 CloudFormation 值)。
In this case "isDev" is acting as "parameter DatabaseStack is blank" in the OP question.在这种情况下,“isDev”在 OP 问题中充当“参数 DatabaseStack 为空白”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.