amazon-web-servicesaws-lambdaterraformaws-event-bridge

Creating a schedule expression for eventbridge using terraform


I am creating resources on AWS using TF and running into an error while trying to create an event bridge scheduler.

Based on TF documentation itself,

schedule_expression = "rate(1 hours)"

Since, I want the event bridge to fire at 8:30am every morning on weekdays and also 5:30pm on weekdays, I used the expression below

schedule_expression = "rate(30 8,17 ? * 2-6 *)"

My pipeline constantly returns this error saying expression is invalid

creating AWS EventBridge Scheduler Schedule (auto-stop-ec2): operation error Scheduler: CreateSchedule, https response error StatusCode: 400, RequestID: baea3d64-f093-4394-a598-509f959c7010, ValidationException: Invalid Schedule Expression rate(30 8,17 ? * 2-6 *).

can any one please offer any advice on what I am doing wrong?


Solution

  • According to Schedule types on EventBridge Scheduler, the syntax to use a Cron-based schedule is the following:

    cron(minutes hours day-of-month month day-of-week year)
    

    I want the event bridge to fire at 8:30am every morning on weekdays and also 5:30pm on weekdays

    Try the following:

    schedule_expression = "cron(30 8,17 ? * MON-FRI *)"
    

    You can validate the above expression using CronHub.