【问题标题】:AWS CloudFormation Error 'Value of property AlarmActions must be of type List of String'AWS CloudFormation 错误“属性 AlarmActions 的值必须是字符串列表类型”
【发布时间】:2020-07-14 15:27:28
【问题描述】:

我正在尝试更新我的 cf 堆栈并在部署时遇到以下错误: '属性 AlarmActions 的值必须是字符串列表类型'

这是属性 AlarmActions:

 AlarmActions:
                - !Ref SparksTeamSNSTopic
                - !If
                    - CreateProdResources
                    - - !Ref SparksProdAlarmSNSTopic
                      - !ImportValue
                          'Fn::Sub': '${Environment}-BMCMajorAlarmTopic'
                    - - !Ref 'AWS::NoValue'                   

【问题讨论】:

  • 您的!If 语法不正确,您能否解释一下!If 的预期结果?
  • 是的,我可以。我希望当我创建产品资源时 SparksProdAlarmSNSTopic 和 ${Environment}-BMCMajorAlarmTopic 将被添加。否则没有参考

标签: amazon-web-services yaml amazon-cloudformation devops


【解决方案1】:

根据 AWS documentationAlarmActions 属性必须包含值,作为字符串列表。所以如果是 JSON,你应该有这样的东西:

"AlarmActions":[
      {"Ref":"ARN of something"},
      {"Ref":"ARN of something"}           
]

但既然你使用过 YAML,你应该有这样的东西:

AlarmActions:
      - !Split [",", !Ref SparksTeamSNSTopic]  <-- make sure SparksTeamSNSTopic contains a list of strings; hence this will split it by comma 

您可以将SparksTeamSNSTopic 定义为

"SparksTeamSNSTopic" : ["topicarn1", "topicarn2"]

【讨论】:

  • 我的主题定义正确。它以前工作得很好......这是我以前的:AlarmActions: - !Ref SparksTeamSNSTopic - !If - CreateProdResources - !Ref SparksProdAlarmSNSTopic - !ImportValue 'Fn::Sub': '${Environment}-BMCCriticalAlarmTopic'
【解决方案2】:

试试这个,

AlarmActions:
    - !Ref SparksTeamSNSTopic
    - !If
      - CreateProdResources
      - - !Ref SparksProdAlarmSNSTopic
        - !ImportValue
            'Fn::Sub': '${Environment}-BMCMajorAlarmTopic'
      - !Ref 'AWS::NoValue'  

【讨论】:

  • 我会试试的。仅据我所知,当条件不满足时,不可能引用字符串列表?
  • 你可以,但不能使用 NoValue。
  • 它有什么问题?
  • AWS::NoValue 就像None
猜你喜欢
  • 2021-12-05
  • 2020-03-25
  • 2020-11-06
  • 1970-01-01
  • 1970-01-01
  • 2021-11-23
  • 1970-01-01
  • 1970-01-01
  • 2018-08-01
相关资源
最近更新 更多