2
votes

I am trying to create an alarm based on anomaly detection model with below CloudFormation template and getting an error :

Can someone help me with this.

"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

2 Answers

4
votes

A per the error, there is a property called name in the alarm definition which is not valid. On a closer look Dimensions array has keys name and value while it should be Name and Value instead as in the example defined here

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

2
votes

As the other answer pointed out, a few properties are capitalized incorrectly. The CloudFormation Linter can help you catch errors like this with helpful error messages like:

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

along with catching another error that "If you specify the Metrics parameter, you cannot specify MetricName, Dimensions, Period, Namespace, Statistic, or ExtendedStatistic":

E2520 Property Dimensions should NOT exist with Metrics for Resources/CPUUtilizationAlarm/Properties
so.json:10:11