AWS Cron Expression Validator

raw JSON →
1.1.15 verified Mon Apr 27 auth: no python

Validates AWS EventBridge cron expressions, which are similar to, but not compatible with Unix style cron expressions. Current version is 1.1.15. Release cadence is irregular.

pip install aws-cron-expression-validator
error ValueError: Invalid cron expression: cron expression must start with 'cron('
cause Passing the expression without the 'cron(' prefix.
fix
Wrap expression: e.g., 'cron(0 12 * * ? *)' instead of '0 12 * * ? *'.
error ValueError: Invalid cron expression: both day-of-week and day-of-month are not '?'
cause Both fields are set to a value other than '?'.
fix
Set one of them to '?', e.g., 'cron(0 12 * * ? *)' or 'cron(0 12 ? * 1)'.
gotcha The library expects the full 'cron(...)' string including the 'cron' prefix, not just the inner expression.
fix Always wrap your expression with 'cron(...)'. Example: 'cron(0 12 * * ? *)'.
gotcha Day-of-week and day-of-month fields cannot both be specified as non-'?' in AWS cron. The library enforces this but may not give a clear error.
fix Use '?' in one of the two fields (day-of-week or day-of-month) as per AWS requirements.
deprecated The library's validation is string-based and may not catch all AWS-specific constraints (e.g., leap years). Future versions may add more checks.
fix Be aware that validation is not exhaustive; test your cron expressions against AWS EventBridge.

Basic usage: validate an AWS EventBridge cron expression.

from aws_cron_expression_validator import validate_cron_expression

cron = 'cron(0 12 * * ? *)'
try:
    validate_cron_expression(cron)
    print('Valid cron expression')
except ValueError as e:
    print(f'Invalid: {e}')