prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  E3021 after upgrading to cfn_lint-0.44.0
  cfn-lint version: cfn_lint-0.44.0
  
  Hi! 
  
  After upgrading to version cfn_lint 0.44.0 don't validate  AWS::Events::Rule
  
  This was reported valid since yesterday:
  
  ```yaml
    TaskSchedule:
      Type: AWS::Events::Rule
      Properties:
        Description: xxxxxxxxx
        Name: !Join ["-", [!Ref EnvironmentName, scheduled, !Ref App]]
        ScheduleExpression: "cron(15 9 * * ? *)"
        State: "ENABLED"
        Targets:
          - Arn:
              Fn::ImportValue: !Sub ${EnvironmentName}-microservice-cluster-arn
            RoleArn: !GetAtt ServiceRole.Arn
            Id: my-task
            EcsParameters:
              TaskCount: 1
              TaskDefinitionArn: !Ref TaskDefinition
  ```
  
  The error reported is: `E3021 An Events Rule can have up to 5 Targets`
  
  There is one Target so should still be valid 
  
  
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/cfnlint/rules/resources/events/RuleTargetsLimit.py`
  Content:
  ```
  1 """
  2 Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3 SPDX-License-Identifier: MIT-0
  4 """
  5 from cfnlint.rules import CloudFormationLintRule
  6 from cfnlint.rules import RuleMatch
  7 
  8 
  9 class RuleTargetsLimit(CloudFormationLintRule):
  10     """Check State Machine Definition"""
  11     id = 'E3021'
  12     shortdesc = 'Check Events Rule Targets are less than or equal to 5'
  13     description = 'CloudWatch Events Rule can only support up to 5 targets'
  14     source_url = 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/cloudwatch_limits_cwe.html'
  15     tags = ['resources', 'events']
  16     max_count = 5
  17 
  18     def __init__(self):
  19         """Init"""
  20         super(RuleTargetsLimit, self).__init__()
  21         self.resource_property_types = ['AWS::Events::Rule']
  22         self.limits = {}
  23 
  24     # pylint: disable=W0613
  25     def check_value(self, value, path):
  26         """Count them up """
  27 
  28         resource_name = path[1]
  29         if len(path) > 4:
  30             if path[4] == 'Fn::If':
  31                 resource_name = '%s.%s' % (path[1], path[5])
  32 
  33         if resource_name not in self.limits:
  34             self.limits[resource_name] = {
  35                 'count': 0,
  36                 'path': path[:-1]
  37             }
  38 
  39         self.limits[resource_name]['count'] += 1
  40         return []
  41 
  42     def match_resource_properties(self, properties, _, path, cfn):
  43         """Check CloudFormation Properties"""
  44         matches = []
  45         matches.extend(
  46             cfn.check_value(
  47                 obj=properties, key='Targets',
  48                 path=path[:],
  49                 check_value=self.check_value
  50             ))
  51 
  52         for _, limit in self.limits.items():
  53             if limit['count'] > self.max_count:
  54                 message = 'An Events Rule can have up to {0} Targets'
  55                 matches.append(RuleMatch(limit['path'], message.format(self.max_count)))
  56 
  57         return matches
  58
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/src/cfnlint/rules/resources/events/RuleTargetsLimit.py b/src/cfnlint/rules/resources/events/RuleTargetsLimit.py
  --- a/src/cfnlint/rules/resources/events/RuleTargetsLimit.py
  +++ b/src/cfnlint/rules/resources/events/RuleTargetsLimit.py
  @@ -21,6 +21,9 @@
           self.resource_property_types = ['AWS::Events::Rule']
           self.limits = {}
   
  +    def initialize(self, cfn):
  +        self.limits = {}
  +
       # pylint: disable=W0613
       def check_value(self, value, path):
           """Count them up """
  
verification_info: {"golden_diff": "diff --git a/src/cfnlint/rules/resources/events/RuleTargetsLimit.py b/src/cfnlint/rules/resources/events/RuleTargetsLimit.py\n--- a/src/cfnlint/rules/resources/events/RuleTargetsLimit.py\n+++ b/src/cfnlint/rules/resources/events/RuleTargetsLimit.py\n@@ -21,6 +21,9 @@\n         self.resource_property_types = ['AWS::Events::Rule']\n         self.limits = {}\n \n+    def initialize(self, cfn):\n+        self.limits = {}\n+\n     # pylint: disable=W0613\n     def check_value(self, value, path):\n         \"\"\"Count them up \"\"\"\n", "issue": "E3021 after upgrading to cfn_lint-0.44.0\ncfn-lint version: cfn_lint-0.44.0\r\n\r\nHi! \r\n\r\nAfter upgrading to version cfn_lint 0.44.0 don't validate  AWS::Events::Rule\r\n\r\nThis was reported valid since yesterday:\r\n\r\n```yaml\r\n  TaskSchedule:\r\n    Type: AWS::Events::Rule\r\n    Properties:\r\n      Description: xxxxxxxxx\r\n      Name: !Join [\"-\", [!Ref EnvironmentName, scheduled, !Ref App]]\r\n      ScheduleExpression: \"cron(15 9 * * ? *)\"\r\n      State: \"ENABLED\"\r\n      Targets:\r\n        - Arn:\r\n            Fn::ImportValue: !Sub ${EnvironmentName}-microservice-cluster-arn\r\n          RoleArn: !GetAtt ServiceRole.Arn\r\n          Id: my-task\r\n          EcsParameters:\r\n            TaskCount: 1\r\n            TaskDefinitionArn: !Ref TaskDefinition\r\n```\r\n\r\nThe error reported is: `E3021 An Events Rule can have up to 5 Targets`\r\n\r\nThere is one Target so should still be valid \r\n\r\n\r\n\n", "before_files": [{"content": "\"\"\"\nCopyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\nSPDX-License-Identifier: MIT-0\n\"\"\"\nfrom cfnlint.rules import CloudFormationLintRule\nfrom cfnlint.rules import RuleMatch\n\n\nclass RuleTargetsLimit(CloudFormationLintRule):\n    \"\"\"Check State Machine Definition\"\"\"\n    id = 'E3021'\n    shortdesc = 'Check Events Rule Targets are less than or equal to 5'\n    description = 'CloudWatch Events Rule can only support up to 5 targets'\n    source_url = 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/cloudwatch_limits_cwe.html'\n    tags = ['resources', 'events']\n    max_count = 5\n\n    def __init__(self):\n        \"\"\"Init\"\"\"\n        super(RuleTargetsLimit, self).__init__()\n        self.resource_property_types = ['AWS::Events::Rule']\n        self.limits = {}\n\n    # pylint: disable=W0613\n    def check_value(self, value, path):\n        \"\"\"Count them up \"\"\"\n\n        resource_name = path[1]\n        if len(path) > 4:\n            if path[4] == 'Fn::If':\n                resource_name = '%s.%s' % (path[1], path[5])\n\n        if resource_name not in self.limits:\n            self.limits[resource_name] = {\n                'count': 0,\n                'path': path[:-1]\n            }\n\n        self.limits[resource_name]['count'] += 1\n        return []\n\n    def match_resource_properties(self, properties, _, path, cfn):\n        \"\"\"Check CloudFormation Properties\"\"\"\n        matches = []\n        matches.extend(\n            cfn.check_value(\n                obj=properties, key='Targets',\n                path=path[:],\n                check_value=self.check_value\n            ))\n\n        for _, limit in self.limits.items():\n            if limit['count'] > self.max_count:\n                message = 'An Events Rule can have up to {0} Targets'\n                matches.append(RuleMatch(limit['path'], message.format(self.max_count)))\n\n        return matches\n", "path": "src/cfnlint/rules/resources/events/RuleTargetsLimit.py"}], "after_files": [{"content": "\"\"\"\nCopyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\nSPDX-License-Identifier: MIT-0\n\"\"\"\nfrom cfnlint.rules import CloudFormationLintRule\nfrom cfnlint.rules import RuleMatch\n\n\nclass RuleTargetsLimit(CloudFormationLintRule):\n    \"\"\"Check State Machine Definition\"\"\"\n    id = 'E3021'\n    shortdesc = 'Check Events Rule Targets are less than or equal to 5'\n    description = 'CloudWatch Events Rule can only support up to 5 targets'\n    source_url = 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/cloudwatch_limits_cwe.html'\n    tags = ['resources', 'events']\n    max_count = 5\n\n    def __init__(self):\n        \"\"\"Init\"\"\"\n        super(RuleTargetsLimit, self).__init__()\n        self.resource_property_types = ['AWS::Events::Rule']\n        self.limits = {}\n\n    def initialize(self, cfn):\n        self.limits = {}\n\n    # pylint: disable=W0613\n    def check_value(self, value, path):\n        \"\"\"Count them up \"\"\"\n\n        resource_name = path[1]\n        if len(path) > 4:\n            if path[4] == 'Fn::If':\n                resource_name = '%s.%s' % (path[1], path[5])\n\n        if resource_name not in self.limits:\n            self.limits[resource_name] = {\n                'count': 0,\n                'path': path[:-1]\n            }\n\n        self.limits[resource_name]['count'] += 1\n        return []\n\n    def match_resource_properties(self, properties, _, path, cfn):\n        \"\"\"Check CloudFormation Properties\"\"\"\n        matches = []\n        matches.extend(\n            cfn.check_value(\n                obj=properties, key='Targets',\n                path=path[:],\n                check_value=self.check_value\n            ))\n\n        for _, limit in self.limits.items():\n            if limit['count'] > self.max_count:\n                message = 'An Events Rule can have up to {0} Targets'\n                matches.append(RuleMatch(limit['path'], message.format(self.max_count)))\n\n        return matches\n", "path": "src/cfnlint/rules/resources/events/RuleTargetsLimit.py"}]}