/aws_cron_expression_validator

Validates AWS EventBridge cron expressions, which are similar to, but not compatible with Unix style cron expressions

Primary LanguagePythonMIT LicenseMIT

PyPI PyPI - Python Version PyPI - Implementation PyPI - Wheel PyPI - Status GitHub issues GitHub license GitHub forks GitHub stars

AWSCronExpressionValidator

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 , - * /

NB: It appears AWS is supporting the Quartz Job Scheduler cron expressions. More details than AWS provides is available in the Cron Trigger Tutorial.

This was inspired by Niloy Chakraborty's AWSCronValidator.py project.

Installing

To install the library run;

pip install aws-cron-expression-validator

Usage

from aws_cron_expression_validator.validator import AWSCronExpressionValidator, AWSCronExpressionMinuteError

my_expression = "0 180 ? * MON-FRI *"
try:
    AWSCronExpressionValidator.validate(my_expression)
except AWSCronExpressionMinuteError:
    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}")