日本語

Creating EventBridge Scheduler Schedules with AWS Emulator

​​AWS Emulator​Amazon EventBridge,Amazon SQS,AWS CLI,IAM,Testing

An EventBridge Scheduler schedule is created with aws scheduler create-schedule, passing "when", "where to send what", and "which role to send it with". If you run AWS Emulator locally, you can confirm the whole path up to a message arriving in an SQS queue at the specified time, without an AWS account. These steps are for trying out things like reminder notifications, jobs that start at a booked time, and daily scheduled runs (cron jobs) in a local environment or in CI.

Note

The test environment was Ubuntu 24.04.5 (x86_64), AWS Emulator 1.0.556 (released November 21, 2026, Debian package), AWS CLI 2.42.1, and jq 1.7. I did not use an AWS account; all requests were sent to the local emulator. In the output, the 12-digit account ID is replaced with <12桁のアカウントID>, and the working directory paths in the commands are omitted. I have not verified how this behaves on real AWS (the actual delivery time offset, retries on failure, pricing, and so on). Where I mention real-AWS behavior, the information comes from the official documentation. For the cron schedule, I only checked creating it; I did not wait to see whether it arrives at the specified time. I have not verified whether a schedule created without --action-after-completion remains afterward. I only tested the standard SQS queue as a target. I did not test other targets such as Lambda, DLQs, schedule groups, StartDate and EndDate, KMS keys, or calls from an SDK.

Flow in which a schedule created with create-schedule uses the execution role to send to the queue at the specified time. Without permission it is not delivered, and AccessDenied appears in the emulator log
Flow from creating a schedule to delivery in the queue (behavior confirmed in the test environment)

Start the emulator and point the AWS CLI at it

I installed AWS Emulator by following the official Linux guide: I verified the Debian package signature with gpg, then installed it with apt-get install. The -t off flag is the option that turns off telemetry.

bash
aws-emulator -t off > emulator.log 2>&1

I keep the emulator log in the file emulator.log so I can check later why a send failed.

With the emulator still running, I opened another terminal and set the environment variables from the official documentation, so the AWS CLI sends requests to the emulator with the emulator's credentials.

bash
export AWS_ENDPOINT_URL=https://127.0.0.1:9297
export AWS_SHARED_CREDENTIALS_FILE=~/.aws/emulator/9297/emulator_credentials
export AWS_CONFIG_FILE=~/.aws/emulator/9297/config
export AWS_CA_BUNDLE=~/.aws/emulator/9297/ca.pem
export AWS_EC2_METADATA_DISABLED=true
export AWS_DISABLE_HOST_PREFIX_INJECTION=true
export AWS_REGION=us-east-1
export AWS_DEFAULT_REGION=us-east-1
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_PROFILE
text
$ aws sts get-caller-identity --query Arn --output text
arn:aws:iam::<12桁のアカウントID>:user/emulator

If user/emulator is returned, you are connected to the emulator.

Create the target queue and the execution role Scheduler uses

As the destination for the schedule, I created the SQS queue reminders.

text
$ aws sqs create-queue --queue-name reminders
{
    "QueueUrl": "https://sqs.us-east-1.amazonaws.com/<12桁のアカウントID>/reminders"
}

EventBridge Scheduler assumes the IAM role specified for each schedule (the execution role) to invoke the target. Following the trust policy in the official guide on creating an execution role, I created a role that allows scheduler.amazonaws.com to assume it.

text
$ cat trust.json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "Service": "scheduler.amazonaws.com" },
    "Action": "sts:AssumeRole"
  }]
}

$ aws iam create-role --role-name scheduler-to-sqs --assume-role-policy-document file://trust.json --query Role.Arn --output text
arn:aws:iam::<12桁のアカウントID>:role/scheduler-to-sqs

The following commands use the queue URL, the queue ARN, and the role ARN, so I stored them in variables.

bash
Q=$(aws sqs get-queue-url --queue-name reminders --query QueueUrl --output text)
QA=$(aws sqs get-queue-attributes --queue-url $Q --attribute-names QueueArn --query Attributes.QueueArn --output text)
RA=$(aws iam get-role --role-name scheduler-to-sqs --query Role.Arn --output text)

At this point the role does not yet have permission to send to the queue. The next section shows what happens without that permission.

Create a one-time schedule using Japan time

A schedule that runs once takes its time in the at(yyyy-mm-ddThh:mm:ss) expression form. If you pass Asia/Tokyo to --schedule-expression-timezone, that time is treated as Japan time. The official documentation says that a one-time schedule is interpreted in UTC or in the time zone specified when it is created.

In the test, I put a value two minutes from now, with the seconds set to 00, into AT1.

text
$ TZ=Asia/Tokyo date "+%Y-%m-%dT%H:%M:%S %Z"
2026-11-22T03:43:38 JST

$ AT1=$(TZ=Asia/Tokyo date -d '+2 minute' +%Y-%m-%dT%H:%M:00)
$ echo $AT1
2026-11-22T03:45:00

For --target, I pass the destination ARN (Arn), the execution role (RoleArn), and the message body (Input) as JSON. Input is a string, so the " characters in the inner JSON are escaped as \". Because the value is inside a double-quoted shell string, it becomes \\\" in the command.

text
$ aws scheduler create-schedule --name reminder-1 \
  --schedule-expression "at($AT1)" \
  --schedule-expression-timezone Asia/Tokyo \
  --flexible-time-window Mode=OFF \
  --target "{\"Arn\":\"$QA\",\"RoleArn\":\"$RA\",\"Input\":\"{\\\"task\\\":\\\"reminder-1\\\"}\"}"
{
    "ScheduleArn": "arn:aws:scheduler:us-east-1:<12桁のアカウントID>:schedule/default/reminder-1"
}

The CreateSchedule reference lists the expression (ScheduleExpression), the target (Target), and the flexible time window (FlexibleTimeWindow) as required. If you want the schedule to run exactly on time without a window, use Mode=OFF.

When I checked the schedule with get-schedule, values were filled in for fields I had not specified.

text
$ aws scheduler get-schedule --name reminder-1
{
    "Arn": "arn:aws:scheduler:us-east-1:<12桁のアカウントID>:schedule/default/reminder-1",
    "GroupName": "default",
    "Name": "reminder-1",
    "ScheduleExpression": "at(2026-11-22T03:45:00)",
    "ScheduleExpressionTimezone": "Asia/Tokyo",
    "State": "ENABLED",
    "CreationDate": "2026-11-21T18:43:39.254622+00:00",
    "LastModificationDate": "2026-11-21T18:43:39.254622+00:00",
    "Target": {
        "Arn": "arn:aws:sqs:us-east-1:<12桁のアカウントID>:reminders",
        "RoleArn": "arn:aws:iam::<12桁のアカウントID>:role/scheduler-to-sqs",
        "RetryPolicy": {
            "MaximumEventAgeInSeconds": 86400,
            "MaximumRetryAttempts": 185
        },
        "Input": "{\"task\":\"reminder-1\"}"
    },
    "FlexibleTimeWindow": {
        "Mode": "OFF"
    },
    "ActionAfterCompletion": "NONE"
}

GroupName was default, and RetryPolicy showed MaximumEventAgeInSeconds as 86400 and MaximumRetryAttempts as 185. In the RetryPolicy reference, both are the maximum values that can be set for those fields.

Without permission, nothing reaches the queue even at the scheduled time

I polled the queue with 20-second long polling seven times (about 140 seconds) across the scheduled time (3:45 AM Japan time), but nothing arrived. The reason appears in the emulator log. I used jq to pull only the WARN lines from emulator.log, which I had saved when starting the emulator. The log also contains lines that are not JSON, so I first used grep '^{' to keep only the JSON lines.

text
$ grep '^{' emulator.log | jq 'select(.level == "WARN") | {time: .timestamp, message: .fields.message, code: .fields.code, detail: .fields.detail}'
{
  "time": "2026-11-21T18:45:00.177170Z",
  "message": "an EventBridge Scheduler invocation failed and its schedule names no dead-letter queue",
  "code": "AccessDenied",
  "detail": "User: arn:aws:sts::<12桁のアカウントID>:assumed-role/scheduler-to-sqs/ffffffffffff4ffe8000000000000001 is not authorized to perform: sqs:sendmessage on resource: arn:aws:sqs:us-east-1:<12桁のアカウントID>:reminders because no identity-based policy allows the sqs:sendmessage action"
}

At 18:45 UTC (3:45 AM Japan time), the role scheduler-to-sqs tried to call sqs:SendMessage, but no policy allowed it, so the call failed with AccessDenied. create-schedule itself succeeded, so the AWS CLI showed no error. If a schedule was created but nothing arrives, the emulator log shows the cause.

The official AWS Emulator documentation says that IAM policies are not evaluated in the same way as on AWS. In the version I tested (1.0.556), sending stopped when the execution role's policy did not allow the action. From this result alone, I cannot tell whether real AWS makes the same decision.

Once sqs:SendMessage is allowed on the role, the message arrives

I attached a policy to the execution role that allows sqs:SendMessage on the queue reminders. The official guide's SQS example uses * for Resource (all queues in the account), but here I limited it to the destination queue.

text
$ cat send.json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": "sqs:SendMessage",
    "Resource": "arn:aws:sqs:us-east-1:<12桁のアカウントID>:reminders"
  }]
}

$ aws iam put-role-policy --role-name scheduler-to-sqs --policy-name send-to-reminders --policy-document file://send.json

I created the schedule reminder-2 for two minutes from now again. I made AT2 with the same date command as AT1. This time I added two things.

The first is --action-after-completion DELETE. In the CreateSchedule reference, this field specifies what happens to the schedule after it finishes invoking the target. You can choose NONE (keep it) or DELETE (remove it). The second is <aws.scheduler.scheduled-time> and <aws.scheduler.attempt-number> in the body. These are called context attributes, and they are replaced with the scheduled time and the attempt number when the message is sent.

text
$ TZ=Asia/Tokyo date "+%Y-%m-%dT%H:%M:%S %Z"
2026-11-22T03:46:07 JST

$ echo $AT2
2026-11-22T03:48:00

$ aws scheduler create-schedule --name reminder-2 \
  --schedule-expression "at($AT2)" \
  --schedule-expression-timezone Asia/Tokyo \
  --flexible-time-window Mode=OFF \
  --action-after-completion DELETE \
  --target "{\"Arn\":\"$QA\",\"RoleArn\":\"$RA\",\"Input\":\"{\\\"task\\\":\\\"reminder-2\\\",\\\"scheduledTime\\\":\\\"<aws.scheduler.scheduled-time>\\\",\\\"attempt\\\":\\\"<aws.scheduler.attempt-number>\\\"}\"}"
{
    "ScheduleArn": "arn:aws:scheduler:us-east-1:<12桁のアカウントID>:schedule/default/reminder-2"
}

$ aws scheduler list-schedules --query "Schedules[].Name"
[
    "reminder-1",
    "reminder-2"
]

After waiting, one message arrived that was sent at 3:48:00 AM Japan time (18:48:00 UTC). The send time is shown to the second. The output below comes from a small test script that prints the send time of the received message (its SentTimestamp converted to UTC) and its body.

text
受信 18:48:00 UTC 送信
{"task":"reminder-2","scheduledTime":"2026-11-21T18:48:00Z","attempt":"1"}

The body was exactly the string I wrote in Input, and the context attributes were replaced with the scheduled time (UTC) and the attempt number 1.

The reminder-2 schedule, which specified DELETE, was removed from the list after it sent. reminder-1, which I did not set to delete and which could not send because of missing permission, remained with State still ENABLED after its time had passed.

text
$ aws scheduler list-schedules --query "Schedules[].Name"
[
    "reminder-1"
]

$ aws scheduler get-schedule --name reminder-2

aws: [ERROR]: An error occurred (ResourceNotFoundException) when calling the GetSchedule operation: Schedule reminder-2 does not exist.
Warning

The official explanation of one-time schedules says that completed one-time schedules still count toward the account quota, and it recommends deleting them once they finish. If you create many schedules, such as for reminders, adding --action-after-completion DELETE saves you from deleting them by hand.

Schedules that repeat on weekday mornings or at fixed intervals

Recurring schedules are written as cron(...) or rate(...). Unlike the Linux crontab, which has five fields, EventBridge Scheduler's cron takes six fields (minute, hour, day of month, month, day of week, year). When I wrote five fields as if it were a crontab, the emulator returned a ValidationException.

text
$ aws scheduler create-schedule --name weekday-9am \
  --schedule-expression "cron(0 9 * * MON-FRI)" \
  --schedule-expression-timezone Asia/Tokyo \
  --flexible-time-window Mode=OFF \
  --target "{\"Arn\":\"$QA\",\"RoleArn\":\"$RA\",\"Input\":\"weekday\"}"

aws: [ERROR]: An error occurred (ValidationException) when calling the CreateSchedule operation: Invalid Schedule Expression cron(0 9 * * MON-FRI).

You also cannot use * for both the day of month and the day of week. If you use * for one, you must use ? for the other. For 9:00 AM on weekdays (Japan time), add a year * and use ? for the day of month, giving cron(0 9 ? * MON-FRI *).

For a job that does not need to run exactly on the minute, I set the flexible time window to FLEXIBLE. According to the official documentation, FLEXIBLE invokes the target at some point within a window of the specified number of minutes from the scheduled time. Without the window size (MaximumWindowInMinutes), creation failed with an error.

text
$ aws scheduler create-schedule --name weekday-9am \
  --schedule-expression "cron(0 9 ? * MON-FRI *)" \
  --schedule-expression-timezone Asia/Tokyo \
  --flexible-time-window Mode=FLEXIBLE \
  --target "{\"Arn\":\"$QA\",\"RoleArn\":\"$RA\",\"Input\":\"weekday\"}"

aws: [ERROR]: An error occurred (ValidationException) when calling the CreateSchedule operation: MaximumWindowInMinutes must be provided when FlexibleTimeWindowMode is set to FLEXIBLE.

$ aws scheduler create-schedule --name weekday-9am \
  --schedule-expression "cron(0 9 ? * MON-FRI *)" \
  --schedule-expression-timezone Asia/Tokyo \
  --flexible-time-window Mode=FLEXIBLE,MaximumWindowInMinutes=15 \
  --target "{\"Arn\":\"$QA\",\"RoleArn\":\"$RA\",\"Input\":\"weekday\"}"
{
    "ScheduleArn": "arn:aws:scheduler:us-east-1:<12桁のアカウントID>:schedule/default/weekday-9am"
}

The official documentation says that for an interval schedule such as rate(5 minutes), if you do not specify a start date (StartDate), invocations begin right away. In the emulator, the time just before creation was 18:48:04 and the first send was at 18:48:05, so the message arrived without waiting.

text
$ date -u +%H:%M:%S
18:48:04

$ aws scheduler create-schedule --name every-5min \
  --schedule-expression "rate(5 minutes)" \
  --flexible-time-window Mode=OFF \
  --target "{\"Arn\":\"$QA\",\"RoleArn\":\"$RA\",\"Input\":\"every-5min\"}"
{
    "ScheduleArn": "arn:aws:scheduler:us-east-1:<12桁のアカウントID>:schedule/default/every-5min"
}
text
受信 18:48:05 UTC 送信
every-5min

When I create a rate schedule in a test, its first message arrives without waiting. If a test counts the messages it receives, include this first one in the count.

Pause or delete a schedule

To pause a schedule temporarily, run update-schedule with --state DISABLED. However, if you pass only --state, the AWS CLI stops with an error about missing required arguments.

text
$ aws scheduler update-schedule --name every-5min --state DISABLED

aws: [ERROR]: An error occurred (ParamValidation): the following arguments are required: --schedule-expression, --target, --flexible-time-window

According to the UpdateSchedule reference, an update replaces the whole schedule with the values you pass, and optional fields you omit return to their default values. The documentation recommends checking the current settings with get-schedule first and passing every field you do not want to change. Here I passed the same expression, window, and target that I used when creating it.

text
$ aws scheduler update-schedule --name every-5min --state DISABLED \
  --schedule-expression "rate(5 minutes)" \
  --flexible-time-window Mode=OFF \
  --target "{\"Arn\":\"$QA\",\"RoleArn\":\"$RA\",\"Input\":\"every-5min\"}"
{
    "ScheduleArn": "arn:aws:scheduler:us-east-1:<12桁のアカウントID>:schedule/default/every-5min"
}

$ aws scheduler list-schedules --query "Schedules[].[Name,State]" --output text
every-5min	DISABLED
reminder-1	ENABLED
weekday-9am	ENABLED

Delete schedules you no longer need with delete-schedule. On success, it prints nothing.

text
$ aws scheduler delete-schedule --name every-5min
$ aws scheduler delete-schedule --name weekday-9am
$ aws scheduler delete-schedule --name reminder-1
$ aws scheduler list-schedules
{
    "Schedules": []
}

AWS Emulator keeps all the resources you create in memory and clears them when it stops. If you restart the emulator for each test, each test starts without any leftover schedules.

​Posted by 86