diff --git a/src/cfnlint/rules/resources/events/RuleScheduleExpression.py b/src/cfnlint/rules/resources/events/RuleScheduleExpression.py index 22661514b5..7dea651476 100644 --- 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 diff --git a/test/fixtures/templates/bad/resources/events/rule_schedule_expression.yaml b/test/fixtures/templates/bad/resources/events/rule_schedule_expression.yaml index b99a839ab1..13d2d2fb08 100644 --- 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 index 35b88ddf2e..9954bcd8ee 100644 --- 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)