skip to Main Content

The TF plan shows the following:

# aws_scheduler_schedule.gh_runners_ubuntu_start["gh_runner_ubuntu"] will be created
  + resource "aws_scheduler_schedule" "gh_runners_ubuntu_start" {
      + arn                          = (known after apply)
      + group_name                   = (known after apply)
      + id                           = (known after apply)
      + name                         = "gh_runners_ubuntu_start-ormos-runner"
      + name_prefix                  = (known after apply)
      + schedule_expression          = "cron(0 23 * * *)"
      + schedule_expression_timezone = "UTC"
      + state                        = "ENABLED"
      + flexible_time_window {
          + mode = "OFF"
        }
      + target {
          + arn      = "arn:aws:scheduler:::aws-sdk:ec2:startInstances"
          + input    = jsonencode(
                {
                  + InstanceIds = [
                      + "i-xxxxxxxxxxxxxxxxx",
                    ]
                }
            )
          + role_arn = "arn:aws:iam::12345678:role/gh_runners_ubuntu_scheduler_role-runner"
        }
    }

Creation fails with:

ValidationException: Invalid Schedule Expression cron(0 23 * * *).

Any ideas?

2

Answers


  1. Check the docs for AWS Cron Syntax. You have 5 values but they use 6. It differs than standard Linux Cron Syntax

    https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html#CronExpressions

    Edit: I believe my suggestion is incorrect and you should look at the one provided by Chris

    Login or Signup to reply.
  2. The terraform docs provide a link to the AWS docs about the schedule expression

    schedule_expression – (Required) Defines when the schedule runs. Read more in Schedule types on EventBridge Scheduler.

    If you reach the cron expression docs it tells you the format is

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

    where the year part is optional. You are passing 5 parameters to cron expression which is correct. However if you read the docs it states

    The * (asterisk) wildcard includes all values in the field. In the Hours field, * includes every hour. You can’t use * in both the Day-of-month and Day-of-week fields. If you use it in one, you must use ? in the other.

    You are using * in both the day-of-mont field and the day-of-week field which is not allowed. Thats why you get invalid expression. you should instead set it as

    schedule_expression          = "cron(0 23 * * ?)"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search