Properties validation failed for resource IotTopicRule2

90 Views Asked by At

My CloudFormation template looks like this:-

 IotTopicRule2:
    Type: 'AWS::IoT::TopicRule'
    Properties:
      RuleName: 'CloudWatchLogsRule'
      TopicRulePayload:
        Sql: "SELECT * FROM 'testtopic'"
        Actions:
          - CloudwatchMetric:
              RoleArn:
                Fn::GetAtt:
                  - 'CloudWatchLogsRole'
                  - 'Arn'

and I am getting this error.

Properties validation failed for resource IotTopicRule2 with message: #/TopicRulePayload/Actions/0/CloudwatchMetric: required key [MetricName] not found #/TopicRulePayload/Actions/0/CloudwatchMetric: required key [MetricValue] not found #/TopicRulePayload/Actions/0/CloudwatchMetric: required key [MetricNamespace] not found #/TopicRulePayload/Actions/0/CloudwatchMetric: required key [MetricUnit] not found

1

There are 1 best solutions below

0
On

It appears that my CloudFormation template is missing some required properties for the CloudwatchMetric action within the IotTopicRule2. The error message indicates that the keys MetricName, MetricValue, MetricNamespace, and MetricUnit are required but not found.

Here is an example of how we can modify this CloudFormation template to include these required properties:

  IotTopicRule2:
  Type: 'AWS::IoT::TopicRule'
  Properties:
    RuleName: 'CloudWatchLogsRule'
    TopicRulePayload:
      Sql: "SELECT * FROM 'testtopic'"
      Actions:
        - CloudwatchMetric:
            RoleArn:
              Fn::GetAtt:
                - 'CloudWatchLogsRole'
                - 'Arn'
            MetricName: 'YourMetricName'
            MetricValue: 'YourMetricValue'
            MetricNamespace: 'YourMetricNamespace'
            MetricUnit: 'YourMetricUnit'

Make sure to replace 'YourMetricName', 'YourMetricValue', 'YourMetricNamespace', and 'YourMetricUnit' with the actual values you want for your CloudWatch Metric. Adjust these values according to your use case.

This modification should resolve the error you are encountering by providing the required keys for the CloudwatchMetric action in the TopicRulePayload.