How to Fix "Parameter ScheduleExpression is not valid" Serverless Error?

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 cron() or rate()) is invalid. To fix the issue, refer to the suggestions under the respective topics:

Fixing cron() Expression Issues

  1. Check if the cron() Expression Syntax and Values Are Correct;
  2. Make Sure You're Not Using * in Both the Day-of-Month and Day-of-Week Fields;
  3. Make Sure the Day-of-Week Field Has One Expression When Using the '#' Character.

Check if the cron() Expression Syntax and Values Are Correct:

The 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:

Field Values Wildcards
Minutes 0-59 , - * /
Hours 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 , - * /

You can learn more about wildcards in the official docs.

For example:

# 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:

3#1,6#3

The correct way would be to only specify one of the two expressions.

Fixing rate() Expression Issues

  1. Check if the rate() Expression Syntax Is Valid;
  2. Make Sure You're Using the Correct Values and Units.

Check if the rate() Expression Syntax Is Valid:

The rate() expression syntax must conform to the following, where both fields are required and must be separated by a white space:

rate(Value Unit)

Where:

  • Value must be a positive integer, and;
  • Unit must 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:

rate(5 minutes)

Make Sure You're Using the Correct Values and Units

  1. At the very least, the rate should be 1 minute.
  2. 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.).

For example:

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.