modalsoul’s blog

これは“失敗”と呼べるかもしれないが、ぼくは“学習体験”と呼びたい

Amazon EventBridgeのcron expressionで最終日(月末/週末)指定がValidationExceptionになる問題

事象

毎月14日および月末日2日前の1:00 のようなたルールを登録する場合、ValidationExceptionでエラーとなる

> aws events put-rule --schedule-expression "cron(0 1 14,L-2 * ? *)" --name samplerule1

An error occurred (ValidationException) when calling the PutRule operation: Parameter ScheduleExpression is not valid.

原因

末日(週末日や月末日)を表すLワイルドカードは、同じくDay-of-monthフィールドに指定している,(カンマ)と併用が不可

ちなみに-(ダッシュ)とも併用できないことを確認

> aws events put-rule --schedule-expression "cron(0 1 10-L-2 * ? *)" --name samplerule1

An error occurred (ValidationException) when calling the PutRule operation: Parameter ScheduleExpression is not valid.

対策

単一のルールでは登録できないので、ルールを分割することで対応した

> aws events put-rule --schedule-expression "cron(0 1 14 * ? *)" --name samplerule1

> aws events put-rule --schedule-expression "cron(0 1 L-2 * ? *)" --name samplerule2