如果CF中的以下if条件是正确的,您能给出建议吗?它是发送调用的SNS主题,如果条件为真则发送消息给前面提到的3个arn.But我在使用数组的时候看到if条件不正确
SnsTopicArns:
!If [firstvalue,
- '{{resolve:ssm:/monitoring/configurationar11:1}}'
- '{{resolve:ssm:/monitoring/configurationarn2:1}}'
- '{{resolve:ssm:/monitoring/configurationarn3:1}}',
- !ImportValue someotheralarm]
发布于 2020-10-01 06:36:52
不幸的是,它的语法是不正确的:
!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
以及问题中没有显示的模板的剩余上下文。
发布于 2020-10-01 13:03:10
如果我没理解错的话,你的逻辑是:
firstvalue
为true,则发送到3个ARNfirstvalue
为false,则使用ARN如果这是正确的,那么您将需要混合使用AWS::NoValue
和您的函数,因为" If“在CloudFormation中不是一个块。它是一个需要应用于您所提供的数组上的每个值的函数。AWS::NoValue
是一种告诉亚马逊网络服务你实际上不想要一个值的方式:如果在属性中使用它,它的行为就像属性没有被设置一样;如果它在数组项中使用,它就像项不存在一样。
我建议你试试这个:
SnsTopicArns:
- !If [ firstvalue, '{{resolve:ssm:/monitoring/configurationarn1:1}}', !Ref AWS::NoValue ]
- !If [ firstvalue, '{{resolve:ssm:/monitoring/configurationarn2:1}}', !Ref AWS::NoValue ]
- !If [ firstvalue, '{{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
https://stackoverflow.com/questions/64145096
复制相似问题