Parameter ScheduleExpression is not valid

I'm trying to setup a Cloudwatch Scheduled Event and my cron expression seems to be invalid, though I can't figure out why.

My cron expression is:

cron(5,15,25,35,45,55 * * * *)

I want it to run on the 5th, 15th, 25th, 35th, 45th and 55th minute of every hour of every day. This seems to coincide with the AWS Scheduled Events documentation here http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html.

The above documentation allows for minutes to be represented with comma separated values between 0 and 59, and hours, day-of-month (or day-of-week), month and year to be reflected with a * wildcard to reflect ALL.

I have tried setting the cron expression on the Lambda console (when creating the function and choosing Cloudwatch Schedule Event), and in the Cloudwatch console (along with choosing the target of the trigger). Neither worked with my custom cron expression.

I have tried the following:

5,15,25,35,45,55 * * * *
5,15,25,35,45,55 * ? * *
cron(5,15,25,35,45,55 * * * *)
cron(5,15,25,35,45,55 * ? * *)

Everytime I get an error saying the ScheduleExpression is not valid. I can, however, use one of the premade rate() expressions.

How can I use my own custom cron expression?

Thanks.


Solution 1:

Could you try : cron(5,15,25,35,45,55 * * * ? *)

Cron expressions have six required fields here.

AWS documentation


EDIT: Also, don't miss this important wildcard note...

You cannot use * in both the Day-of-month and Day-of-week fields. If you use it in one, you must use ? in the other.

Solution 2:

I think this would fit your use-case as well, and offers better legibility: rate(5 minutes)

Or to put it in CloudFormation code:

Resources:
  ChangeDetectFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: example/
      Handler: app.lambda_handler
      Runtime: python3.8
      Events:
        ScheduledEvent:
          Name: Every5min
          Type: Schedule
          Properties:
            Schedule: rate(5 minutes)