AWS CloudFormation失败,错误为“遇到不受支持的属性名称”

时间:2019-11-21 21:53:57

标签: amazon-web-services amazon-cloudformation amazon-cloudwatch cloudwatch-alarms

我正在尝试使用以下CloudFormation模板基于异常检测模型创建警报并收到错误:

有人可以帮我吗?

"Resources": {
    "CPUUtilizationAlarm": {
       "Type": "AWS::CloudWatch::Alarm",
       "Properties": {
          "AlarmDescription": "Alarm Triggered",
          "AlarmName": "CPUUtilizationAlarm",
          "ComparisonOperator": "GreaterThanUpperThreshold",
          "EvaluationPeriods": 1,
          "Dimensions": [],
          "Metrics": [
             {
                "Expression": "ANOMALY_DETECTION_BAND(m1, 10)",
                "Id": "ad1"
             },
             {
                "Id": "m1",
                "MetricStat": {
                   "Metric": {
                      "MetricName": "CPUUtilization",
                      "Namespace": "AWS/EC2",
                      "Dimensions": [
                        {
                          "value": "i-05157fe1be36d52bd",
                          "name": "InstanceId"
                        }
                      ],
                    },
                   "Period": 60,
                   "Stat": "Average"
                }
             }
          ],
          "ThresholdMetricId": "ad1",
          "TreatMissingData": "breaching",
       }
    }
 }

2 个答案:

答案 0 :(得分:3)

对于每个错误,警报定义中都有一个名为name的属性,该属性无效。仔细观察,Dimensions数组具有键namevalue,而应分别为NameValue,而不是此处定义的示例中的

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-dimension.html

答案 1 :(得分:1)

正如另一个答案所指出的那样,一些属性被错误地大写。 The CloudFormation Linter可以通过以下有用的错误消息来帮助您捕获此类错误:

    open System.Collections.Concurrent

    let _MessageQueue = ConcurrentQueue<string>()
    let messages = ResizeArray<string>()
    let mutable continueLooping = true
    while continueLooping do
        let success, message = _MessageQueue.TryDequeue()
        messages.Add(message)
        continueLooping <- success

伴随着另一个错误"If you specify the Metrics parameter, you cannot specify MetricName, Dimensions, Period, Namespace, Statistic, or ExtendedStatistic"

E3003 Property Name missing at Resources/CPUUtilizationAlarm/Properties/Metrics/1/MetricStat/Metric/Dimensions/0
so.json:22:25

E3003 Property Value missing at Resources/CPUUtilizationAlarm/Properties/Metrics/1/MetricStat/Metric/Dimensions/0
so.json:22:25

E3002 Invalid Property Resources/CPUUtilizationAlarm/Properties/Metrics/1/MetricStat/Metric/Dimensions/0/value
so.json:23:27

E3002 Invalid Property Resources/CPUUtilizationAlarm/Properties/Metrics/1/MetricStat/Metric/Dimensions/0/name
so.json:24:27