'AWS SAM ScheduledEvent error: "Parameter ScheduleExpression is not valid"

I'm trying to setup an EventBridge Scheduled Event for my Lambda Function using the SAM CLI.

My desired cron expression is:

cron(0 0 * * ? *)

My template.yml file:

Events:
  ScheduledEvent:
    Type: Schedule
    Properties:
      # Every day at 0:00
      Schedule: cron(0 0 * * ? *)

I've tried setting the cron expression on the AWS console and it's considered valid.

I've tried these other expressions in my template.yml file:

cron(0 0 * * ? *)
cron(0 0 * * * *)
cron(0 0 ? * * *)
cron(0 1 * * ? *)
cron(1 1 * * ? *)
0 0 * * ? *
"cron(0 0 * * ? *)"

but they always return the same error when I try to deploy the stack.

What's the error in my cron expression?



Solution 1:[1]

I deployed a sample Node.js function from this repository https://github.com/awsdocs/aws-lambda-developer-guide/tree/main/sample-apps/blank-nodejs after adding the event config to its template. This is the event config I added:

Events:
  ScheduledEvent:
    Type: Schedule
    Properties:
      # Every day at 0:00
      Schedule: cron(0 0 * * ? *)

It worked and after that I tried to deploy my original function (with no changes to its template). Now my function was deployed successfully.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 raxaghi