AWS CF!如果失败

时间:2020-04-07 15:06:52

标签: yaml amazon-cloudformation devops

当条件满足时,我的AWS CF失败。 这意味着当CreateProdResources为true时,我会收到以下错误:

Value of property AlarmActions must be of type List of String
AlarmActions:
                - !Ref SparksTeamSNSTopic
                - !If
                    - CreateProdResources
                    - - !Ref SparksProdAlarmSNSTopic
                      - !ImportValue
                          'Fn::Sub': '${Environment}-BMCCriticalAlarmTopic'
                    - !Ref 'AWS::NoValue'

1 个答案:

答案 0 :(得分:0)

尝试下面的模板,我还包括2种不同的!if条件处理方法。

从上面的问题的代码片段中我可以看到,您正在尝试使用条件将 2个主题包括在单个列表项中,从而导致错误 AlarmActions的类型必须为字符串列表。因此,您需要将2个主题分成2个列表项,如我所示。

AlarmActions:
  - !Ref CloudtrailAlarmNotification
  - !If
    - CreateProdResources
    - Fn::ImportValue:
        !Sub 'RestAPI-${PartnerDataEndpointResource}-URLendpoint-${Stage}'
    - !Ref 'AWS::NoValue'
  - !If [CreateProdResources, !Ref SparksProdAlarmSNSTopic, !Ref 'AWS::NoValue']