Possible bug with scheduled event definitions

When trying to create a function that is triggered from a cloudwatch rule the following works:

events:
  - schedule: 
      rate: rate(60 minutes) 
      name: "my-scheduled-thing"
      description: "Does a thing on a scheduled basis"
      enabled: true

But this does not:

events:
  - schedule: 
      rate: cron(0 * * * *)
      name: "my-scheduled-thing"
      description: "Does a thing on a scheduled basis"
      enabled: true

In the latter case I get an error: “rate” property for schedule event is missing or invalid in function ScheduledDL.

The environment:
OS: win32
Node Version: 10.15.3
Serverless Version: 1.36.3

In this case it isn’t critical for me as the use of rate is acceptable (though not as ideal since cron allows me to specify the exact minute) but in many other cases this won’t be a usable trade-off.

As an additional side note, it will accept:

events:
  - schedule: 
    rate: cron(0 * * * *)
    name: "my-scheduled-thing"
    description: "Does a thing on a scheduled basis"
    enabled: true

But of course this isn’t properly indented so the schedule never gets created.

(edited to fix formatting)

See the AWS Documentation for CloudWatch Schedule Expressions

The specific rule you want to notice is:

  • The * (asterisk) wildcard includes all values in the field. In the Hours field, * would include every hour. 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.

That’s a good point on the cron expression, but it doesn’t help with the general parsing issue. With proper indentation serverless is complaining about the rate property missing. With improper indentation it (rightly, but confusingly as it send no warning) just ignores the schedule.

I know this is old but I just ran into the same issue so I’ll leave the answers for others if they make the same mistake I did.

The AWS schedule syntax is not standard cron and they really shouldn’t call it that. https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html

It has an extra field at the end to specify the year so a proper AWS schedule syntax has 6 fields and would look like:

events:
  - schedule: 
    rate: cron(0 * * * ? *)
    name: "my-scheduled-thing"
    description: "Does a thing on a scheduled basis"
    enabled: true