Home > OS >  AWS Cron schedule expression
AWS Cron schedule expression

Time:04-05

I want to deploy function to AWS Lambda with using serverless framework in NodeJS/Typescript. Here is my serverless.yml:

service: backend

plugins:
  - serverless-webpack

provider:
  name: aws
  region: eu-central-1
  runtime: nodejs14.x
  stage: dev

functions:
  createDailyStatistics:
    handler: dist/services/schedules.scheduleDailyStatistics
    events:
      - schedule:
          rate: cron(0 0 * * *)
          enabled: true

can someone tell me, why after launch serverless deploy i got an error like this:

CREATE_FAILED: CreateDailyStatisticsEventsRuleSchedule1 (AWS::Events::Rule)
Parameter ScheduleExpression is not valid. (Service: AmazonCloudWatchEvents; Status Code: 400; Error Code: ValidationException; Request ID: xxx; Proxy: null)

My expression - 0 0 * * * is a standard cron expression but AWS not handle this? I want to launch this functino on every day at midnight.

Thanks for any help!

CodePudding user response:

AWS uses the extended CRON expression format:

enter image description here

Please notice, there are 6 fields in the expression: Minutes, Hours, Day of month, Month, Day of week and Year.

In your case, you provide only 5 values. I'm guessing you were most likely using crontab.guru to create your cron expression, meaning that you want an event to fire At 00:00. In that case, for AWS you would want to have something like this: 0 0 * * ? *.

  • Related