如何解决如果条件形成云
如果CF中的以下IF条件正确,能否请您提出建议。 它是发送呼叫SNS主题,如果条件为true,则将消息发送到提到的3 arn。但是我看到他,如果使用数组时条件不正确
SnsTopicArns:
!If [firstvalue,- '{{resolve:ssm:/monitoring/configurationar11:1}}'
- '{{resolve:ssm:/monitoring/configurationarn2:1}}'
- '{{resolve:ssm:/monitoring/configurationarn3:1}}',- !ImportValue someotheralarm]
解决方法
遗憾的是,它的语法不正确:
!If [condition_name,value_if_true,value_if_false]
因此,您可以尝试以下操作:
SnsTopicArns:
!If
- firstvalue,- - '{{resolve:ssm:/monitoring/configurationar11:1}}'
- '{{resolve:ssm:/monitoring/configurationarn2:1}}'
- '{{resolve:ssm:/monitoring/configurationarn3:1}}'
- !ImportValue someotheralarm
请注意,根据someotheralarm
是什么,以及问题中未显示的模板的其余上下文,您的模板仍然可能会失败。
如果我理解正确,那么您的逻辑是:
- 如果
firstvalue
为真,则发送到3个ARN - 如果
firstvalue
为假,则使用!ImportValue
如果这是正确的,那么您将需要混合使用AWS::NoValue
和函数,因为“ If”不是CloudFormation中的块。此功能需要应用于您提供的数组上的每个值。 AWS::NoValue
是一种告诉AWS您实际上不希望在其中存在值的方法:如果该值在属性中使用,它的行为就像未设置该属性一样;如果用于数组项目中,则其行为就好像该项目不存在。
我建议您尝试一下:
SnsTopicArns:
- !If [ firstvalue,'{{resolve:ssm:/monitoring/configurationarn1:1}}',!Ref AWS::NoValue ]
- !If [ firstvalue,'{{resolve:ssm:/monitoring/configurationarn2:1}}','{{resolve:ssm:/monitoring/configurationarn3:1}}',!Ref AWS::NoValue ]
- !If [ !Not [ firstvalue ],!ImportValue someotheralarm,!Ref AWS::NoValue ]
更新: 我正在做一些测试,我相信这也可以:
SnsTopicArns:
Fn::If:
- firstvalue
- - '{{resolve:ssm:/monitoring/configurationarn1:1}}'
- '{{resolve:ssm:/monitoring/configurationarn2:1}}'
- '{{resolve:ssm:/monitoring/configurationarn3:1}}'
- - !ImportValue someotheralarm
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。