If you're encountering the serverless error, "
Parameter ScheduleExpression is not valid" while trying to setup an AWS CloudWatch scheduled event, it means that the schedule expression(s) you're using (i.e. one of, either
rate()) is invalid. To fix the issue, refer to the suggestions under the respective topics:
cron() Expression Issues
- Check if the
cron()Expression Syntax and Values Are Correct;
- Make Sure You're Not Using
*in Both the Day-of-Month and Day-of-Week Fields;
- Make Sure the Day-of-Week Field Has One Expression When Using the '#' Character.
Check if the
cron() Expression Syntax and Values Are Correct:
cron() expression syntax should conform to the following, where all six fields are required and must be separated by a white space:
cron(Minutes Hours Day-of-Month Month Day-of-Week Year)
Each field can have the following values/wildcards:
You can learn more about wildcards in the official docs.
# Run at 10:15 am (UTC) every day cron(15 10 * * ? *) # Run at 6:00 pm (UTC) every Monday through Friday cron(0 18 ? * MON-FRI *) # Run at 8:00 am (UTC) every 1st day of the month cron(0 8 1 * ? *) # Run every 15 minutes Monday to Friday between 10:00 am and 4:45 pm (UTC) cron(0/15 10-16 ? * MON-FRI *)
Make Sure You're Not Using
* in Both the Day-of-Month and Day-of-Week Fields:
According to the official docs, you cannot use the
* (asterisk) wildcard for both, "Day-of-Month" and "Day-of-Week" fields in the same
cron() expression. If the expression you're using contains
* for both fields, then you must replace one of them with
? (question mark). For example, the following expressions are valid:
cron(15 10 * * ? *) cron(15 10 ? * * *)
Make Sure the Day-of-Week Field Has One Expression When Using the '#' Character
According to the official docs, you cannot use multiple expressions in the Day-of-Week field when you're using "
#" character. You may only define one expression in such a case. For example, the following is invalid:
The correct way would be to only specify one of the two expressions.
rate() Expression Issues
- Check if the
rate()Expression Syntax Is Valid;
- Make Sure You're Using the Correct Values and Units.
Check if the
rate() Expression Syntax Is Valid:
rate() expression syntax must conform to the following, where both fields are required and must be separated by a white space:
Valuemust be a positive integer, and;
Unitmust be defined in either minute(s), hour(s), or day(s);
For example, the following expression would trigger at a rate of every five minutes:
Make Sure You're Using the Correct Values and Units
- At the very least, the rate should be 1 minute.
- For singular values (such as 1 minute, 1 hour, etc.), the unit must be singular and for values greater than 1 the unit must be plural (such as 2 minutes, 2 hours, etc.).
rate(1 hour) rate(2 hours) rate(1 day) rate(2 days)
This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.