Sub topic 15
Scheduled invocations and EventBridge Scheduler
This chapter assumes you can create EventBridge rules and targets with the AWS CLI, read IAM policies and trust policies, and invoke a Lambda function or write to an SQS queue. Earlier chapters covered rules, targets, and permissions. This chapter applies them to time-based triggers.
Two ways to run something on a schedule
EventBridge offers two features for time-based invocation:
- Scheduled rules are ordinary rules on the default event bus. Instead of an event pattern, they carry a schedule expression.
- EventBridge Scheduler is a separate service with its own API (
aws scheduler). It is built for large numbers of schedules, time zones, and one-time invocations.
AWS recommends Scheduler for new work. You still need to understand scheduled rules, because many existing systems use them and they fit cleanly into the event-bus model.
| Capability | Scheduled rule | EventBridge Scheduler |
|---|---|---|
| API | `aws events put-rule` | `aws scheduler create-schedule` |
| Bus required | Default bus only | None |
| Time zone | UTC only | Any IANA time zone, with daylight saving handled |
| One-time schedule | No | Yes, with `at()` |
| Flexible time window | No | Yes, up to 1,440 minutes |
| Targets | Rule targets (about 20 service types) | Templated targets plus universal targets for most AWS API actions |
| Retries and DLQ | Per target | Per schedule |
| Scale | Rule quota per account and region | Millions of schedules |
| Permissions | Resource policy on the target, or a role | Always an execution role |
Schedule expressions
Both features use the same two expression types.
A rate expression runs at a fixed interval:
rate(5 minutes)rate(1 hour)rate(7 days)
Use the singular unit when the value is 1, and the plural otherwise. rate(1 hours) is rejected.
A cron expression has six fields: cron(minutes hours day-of-month month day-of-week year). Two rules cause most of the errors:
- You must put
?in either day-of-month or day-of-week, and a real value in the other. - There is no seconds field. The finest granularity is one minute.
| Expression | Meaning |
|---|---|
| `cron(0 2 * * ? *)` | Every day at 02:00 |
| `cron(0/15 * * * ? *)` | Every 15 minutes, starting at minute 0 |
| `cron(30 8 ? * MON-FRI *)` | 08:30 on weekdays |
| `cron(0 0 1 * ? *)` | Midnight on the first day of each month |
Scheduler adds a third type, at(yyyy-mm-ddThh:mm:ss), for a single invocation. It has no trailing Z, because the time zone comes from a separate setting.
Scheduled rules
A scheduled rule is created like any other rule, with --schedule-expression in place of --event-pattern. It must live on the default bus.
aws events put-rule \
--name nightly-report \
--schedule-expression "cron(0 2 * * ? *)"
aws events put-targets \
--rule nightly-report \
--targets '[{"Id":"report-fn","Arn":"arn:aws:lambda:us-east-1:123456789012:function:report"}]'
aws lambda add-permission \
--function-name report \
--statement-id allow-nightly-report \
--action lambda:InvokeFunction \
--principal events.amazonaws.com \
--source-arn arn:aws:events:us-east-1:123456789012:rule/nightly-reportThe add-permission call is the resource-policy step from the permissions chapter. Without it the rule fires but Lambda rejects the invocation.
The event delivered to the target has source set to aws.events and detail-type set to Scheduled Event. The detail field is empty. If the target needs parameters, set a constant input on the target or use an input transformer.
Scheduled rules have these limitations:
- Times are in UTC, so a "02:00 local time" job shifts by an hour twice a year.
- Invocation is at-least-once and can be delayed by a short time, so handlers must be idempotent.
- There is no way to run something once. You would have to create a rule and delete it yourself.
- Each rule counts against your per-region rule quota, which makes per-customer or per-record schedules impractical.
EventBridge Scheduler
A schedule belongs to a schedule group, a container for organizing schedules and tagging them. Schedules go into the default group unless you create another. Each schedule has four main parts:
- A schedule expression and, optionally, a time zone.
- A flexible time window setting.
- A target, which includes the ARN, an execution role, and optional input.
- A retry policy and optional dead-letter queue.
The execution role
Scheduler always invokes the target by assuming an IAM role that you supply. Its trust policy must name the Scheduler service principal:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "scheduler.amazonaws.com" },
"Action": "sts:AssumeRole"
}
]
}The role's permissions policy grants only what the target needs, such as lambda:InvokeFunction on one function. If the schedule has a dead-letter queue, the role also needs sqs:SendMessage on that queue.
A recurring schedule in a time zone
aws scheduler create-schedule \
--name nightly-report \
--schedule-expression "cron(0 2 * * ? *)" \
--schedule-expression-timezone "America/New_York" \
--flexible-time-window Mode=OFF \
--target '{
"Arn": "arn:aws:lambda:us-east-1:123456789012:function:report",
"RoleArn": "arn:aws:iam::123456789012:role/scheduler-invoke-role",
"Input": "{\"reportType\":\"daily\"}",
"RetryPolicy": {"MaximumRetryAttempts": 3, "MaximumEventAgeInSeconds": 3600},
"DeadLetterConfig": {"Arn": "arn:aws:sqs:us-east-1:123456789012:scheduler-dlq"}
}'This runs at 02:00 New York time all year. Scheduler adjusts for daylight saving. The --flexible-time-window option is required. Mode=OFF means invoke at the exact time.
Unlike a rule target, the Input is delivered to the target as-is. There is no EventBridge event envelope around it. Your Lambda function receives {"reportType":"daily"} directly.
One-time schedules
Use at() for a single future invocation, such as a reminder or a delayed cleanup:
aws scheduler create-schedule \
--name close-promo-2026 \
--schedule-expression "at(2026-12-24T09:00:00)" \
--schedule-expression-timezone "Europe/Berlin" \
--flexible-time-window Mode=OFF \
--action-after-completion DELETE \
--target '{
"Arn": "arn:aws:lambda:us-east-1:123456789012:function:close-promo",
"RoleArn": "arn:aws:iam::123456789012:role/scheduler-invoke-role",
"Input": "{\"promoId\":\"xmas-2026\"}"
}'With --action-after-completion DELETE, Scheduler removes the schedule once it has run, so finished schedules do not pile up.
Flexible time windows
If many schedules fire at the same minute, such as cron(0 * * * ? *) across thousands of tenants, the targets see a burst. A flexible window tells Scheduler to invoke at a random point inside the window:
--flexible-time-window Mode=FLEXIBLE,MaximumWindowInMinutes=15Use it for work that tolerates jitter. Do not use it for anything that must start at a precise time.
Universal targets
Templated targets cover common services such as Lambda, SQS, SNS, and Step Functions. A universal target calls almost any AWS API action. Its ARN has the form arn:aws:scheduler:::aws-sdk:<service>:<apiAction>, and Input holds the request parameters as JSON. For example, to send an SQS message on a schedule, use arn:aws:scheduler:::aws-sdk:sqs:sendMessage with {"QueueUrl":"...","MessageBody":"..."}. The execution role needs the matching IAM action, here sqs:SendMessage.
Scheduler can also target an event bus, which connects schedules back to the rest of this tutorial. Set the target ARN to a bus and give the role events:PutEvents. The Input becomes the event, so you must supply a JSON object with Source, DetailType, and Detail. Rules on that bus then route the event like any other.
How the pieces fit
Failure modes and gotchas
- Missing
?in cron.cron(0 2 * * * *)is invalid. Put?in day-of-month or day-of-week. - Wrong time zone assumption. Scheduled rules are always UTC. A cron expression copied from a rule into Scheduler without a time zone is also UTC.
- Past
at()times. A one-time schedule set in the past never runs usefully. Check the time and its zone before creating it. - Role problems. If a schedule shows failed invocations, check that the role trust policy names
scheduler.amazonaws.comand that the role allows the exact target action. - Duplicate invocations. Both features deliver at least once. Make handlers idempotent, for example by keying work on the scheduled date.
- Retries and the dead-letter queue. Scheduler's retry policy defaults to 185 attempts over 24 hours. Set
MaximumRetryAttemptsandMaximumEventAgeInSecondsexplicitly if a stale invocation is worse than a missed one.
Monitoring
Scheduled rules report the same CloudWatch metrics as other rules in the AWS/Events namespace, including Invocations and FailedInvocations. Scheduler publishes metrics in AWS/Scheduler, including TargetErrorCount and InvocationDroppedCount, and InvocationsSentToDeadLetterCount when a DLQ is configured. Alarm on error counts and on messages arriving in the DLQ, since a silent scheduled job is easy to miss.
Exercise
A team needs a job to run at 07:00 every weekday in Sydney time, all year, and a second job to run exactly once on 2027-03-01 at 12:00 and then clean up after itself. Which service should they use, and what expressions and settings do they need?
Show answer
Use EventBridge Scheduler, because scheduled rules are UTC only and cannot run once. For the weekday job, use cron(0 7 ? * MON-FRI *) with --schedule-expression-timezone "Australia/Sydney", so daylight saving is handled automatically. For the one-time job, use at(2027-03-01T12:00:00) with a time zone, and set --action-after-completion DELETE so the schedule removes itself. Both need --flexible-time-window Mode=OFF and an execution role that trusts scheduler.amazonaws.com and allows the target action.
Exercise
A scheduled rule on the default bus fires on time, but its Lambda target never runs. What is the most likely cause, and how do you fix it?
Show answer
The Lambda function probably has no resource-based permission for events.amazonaws.com, so Lambda rejects the invocation. Fix it with aws lambda add-permission using principal events.amazonaws.com and the rule's ARN as --source-arn. The rule's FailedInvocations metric rising confirms the diagnosis.