Validates these AWS EventBridge cron expressions, which are similar to, but not compatible with Unix style cron expressions;
| Field | Values | Wildcards |
|---|---|---|
| Minute | 0-59 | , - * / |
| Hour | 0-23 | , - * / |
| Day-of-month | 1-31 | , - * ? / L W |
| Month | 1-12 or JAN-DEC | , - * / |
| Day-of-week | 1-7 or SUN-SAT | , - * ? L # |
| Year | 1970-2199 | , - * / |
- It appears AWS's wildcard support borrows heavily from Quartz Job Scheduler cron expressions. More documentation about wildcard handling than AWS provides is available in the Cron Trigger Tutorial. NB: AWS doesn't support seconds (i.e. AWS has 6 fields, while Quartz has 7), so ignore the first field in the Quartz documenation.
This was inspired by Niloy Chakraborty's AWSCronValidator.py project.
To install the library run;
pip install aws-cron-expression-validatorfrom aws_cron_expression_validator.validator import AWSCronExpressionValidator, AWSCronExpressionMinuteError
my_expression = "0 180 ? * MON-FRI *"
try:
AWSCronExpressionValidator.validate(my_expression)
except AWSCronExpressionMinuteError as e:
print(f"Oh no! My expression has an invalid minute field: {e}")
except ValueError as e:
print(f"Oh no! My expression was invalid: {e}")