Repository: aws-cloudformation/cfn-lint

Issue:
AWS::Events::Rule ScheduleExpression: "cron(* 1 * * * *)" 
*cfn-lint version: (cfn-lint 0.27.5)*

*Description of issue.*

```
  EventRule:
    Type: "AWS::Events::Rule"
    Properties:
      ScheduleExpression: "cron(* 1 * * * *)" 
      State: "ENABLED"
      Targets:
        - Arn: !Ref Foo
          Id: "Foo"
          RoleArn: !GetAtt FooArn.Arn
```

Check should be probably in:

[src/cfnlint/rules/resources/events/RuleScheduleExpression.py](https://github.com/aws-cloudformation/cfn-python-lint/blob/master/src/cfnlint/rules/resources/events/RuleScheduleExpression.py)

The above `ScheduleExpression` is invalid (need a value for minute if hour is set). For example `cron(0 1 * * ? *)`

---

[Schedule Expressions for Rules documentation](https://docs.aws.amazon.com/eventbridge/latest/userguide/scheduled-events.html)


Discussion:
@jtheuer I can get `* 1 * * ? *` to work.  Are you getting an error in this situation?  I'm seeing this in the documentation.
```
You can't specify the Day-of-month and Day-of-week fields in the same cron expression.
If you specify a value (or a *) in one of the fields, you must use a ? (question mark) in the other. 
```

Which was also corrected in your example and seems like an easy rule we can write.  Thoughts?

Resolving patch:
diff --git a/src/cfnlint/rules/resources/events/RuleScheduleExpression.py b/src/cfnlint/rules/resources/events/RuleScheduleExpression.py
--- a/src/cfnlint/rules/resources/events/RuleScheduleExpression.py
+++ b/src/cfnlint/rules/resources/events/RuleScheduleExpression.py
@@ -37,7 +37,8 @@ def check_rate(self, value, path):
                 # Check the Value
                 if not items[0].isdigit():
                     message = 'Rate Value ({}) should be of type Integer.'
-                    extra_args = {'actual_type': type(items[0]).__name__, 'expected_type': int.__name__}
+                    extra_args = {'actual_type': type(
+                        items[0]).__name__, 'expected_type': int.__name__}
                     matches.append(RuleMatch(path, message.format(items[0]), **extra_args))
 
         return matches
@@ -57,6 +58,12 @@ def check_cron(self, value, path):
             if len(items) != 6:
                 message = 'Cron expression must contain 6 elements (Minutes Hours Day-of-month Month Day-of-week Year), cron contains {} elements'
                 matches.append(RuleMatch(path, message.format(len(items))))
+                return matches
+
+            _, _, day_of_month, _, day_of_week, _ = cron_expression.split(' ')
+            if day_of_month != '?' and day_of_week != '?':
+                matches.append(RuleMatch(
+                    path, 'Don\'t specify the Day-of-month and Day-of-week fields in the same cron expression'))
 
         return matches
 


Test patch:
diff --git a/test/fixtures/templates/bad/resources/events/rule_schedule_expression.yaml b/test/fixtures/templates/bad/resources/events/rule_schedule_expression.yaml
--- a/test/fixtures/templates/bad/resources/events/rule_schedule_expression.yaml
+++ b/test/fixtures/templates/bad/resources/events/rule_schedule_expression.yaml
@@ -29,3 +29,7 @@ Resources:
     Type: AWS::Events::Rule
     Properties:
       ScheduleExpression: "cron(0 */1 * * WED)" # Not enough values
+  MyScheduledRule8:
+    Type: AWS::Events::Rule
+    Properties:
+      ScheduleExpression: "cron(* 1 * * * *)" # specify the Day-of-month and Day-of-week fields in the same cron expression
diff --git a/test/unit/rules/resources/events/test_rule_schedule_expression.py b/test/unit/rules/resources/events/test_rule_schedule_expression.py
--- a/test/unit/rules/resources/events/test_rule_schedule_expression.py
+++ b/test/unit/rules/resources/events/test_rule_schedule_expression.py
@@ -24,4 +24,4 @@ def test_file_positive(self):
     def test_file_negative_alias(self):
         """Test failure"""
         self.helper_file_negative(
-            'test/fixtures/templates/bad/resources/events/rule_schedule_expression.yaml', 7)
+            'test/fixtures/templates/bad/resources/events/rule_schedule_expression.yaml', 8)