How to run periodic jobs on AWS: EC2 cron, EventBridge Scheduler and which target to use
A periodic job on AWS runs in one of two ways. Either a server you already have runs it with cron or a systemd timer, or Amazon EventBridge Scheduler calls an AWS API on a schedule: it invokes a Lambda function, starts an ECS task, submits an AWS Batch job or starts a Step Functions workflow. Which one fits depends mostly on how long a run takes and how much infrastructure you want to own.
This page is the overview: how to choose, how a schedule works, and what to set so failures don't go unnoticed. For packaging and deploying a scheduled function, see the companion guide to scheduling AWS Lambda functions. Everything below was checked against the AWS documentation and pricing pages in November 2026.
Key takeaways
- A job tied to one server can stay in cron or a systemd timer on that EC2 instance. Amazon Linux 2023 ships without crontab.
- For everything else, use EventBridge Scheduler: one schedule per job, an execution role it assumes, and one target API. AWS now calls the older scheduled rules legacy.
- Choose the target by run time first: a standard Lambda function stops at 15 minutes, an ECS task or Batch job runs until it exits.
- AWS cron has six fields, needs
?in day-of-month or day-of-week, and counts weekdays from Sunday = 1. - Delivery is at least once. Every job must be safe to run twice.
The options at a glance
Five places can run the work. They differ in how long a run may take, how you pay and what you maintain.
| Where the job runs | Longest single run | What you pay for | What you maintain |
|---|---|---|---|
| Cron or a systemd timer on EC2 | No limit | The instance, every hour it is running | The instance: patching, disk, restarts |
| Scheduler → Lambda | 15 minutes | Requests and GB-seconds | The function and its role |
| Scheduler → ECS task on Fargate | Until the container exits | vCPU and memory per second | Image, task definition, VPC networking |
| Scheduler → AWS Batch | Until the job exits | The EC2 or Fargate capacity Batch starts | Compute environment, job queue, job definition |
| Scheduler → Step Functions | One year (Standard), five minutes (Express) | State transitions (Standard) | The state machine and what it calls |
Run time is the constraint you can't negotiate: a 40-minute job does not fit into a service that stops it at 15. Answer the questions in order:
Cron on an EC2 instance
If the job needs software, files or credentials that already live on one instance, schedule it there. The catch: Amazon Linux 2023 does not include the cronie package, so unlike Amazon Linux 2 it has no crontab out of the box. AWS recommends systemd timers and warns that a future Amazon Linux may drop classic cron entirely.
A timer takes two small unit files. Save the service, which says what to run, as /etc/systemd/system/nightly-report.service:
[Unit]
Description=Nightly report
[Service]
Type=oneshot
ExecStart=/usr/local/bin/nightly-report
Save the timer, which says when, as /etc/systemd/system/nightly-report.timer. It starts the service with the same name:
[Unit]
Description=Run the nightly report at 03:30
[Timer]
OnCalendar=*-*-* 03:30:00
Persistent=true
[Install]
WantedBy=timers.target
Load and start it, check the next run, and read past output:
sudo systemctl daemon-reload
sudo systemctl enable --now nightly-report.timer
systemctl list-timers nightly-report.timer
journalctl -u nightly-report.service
Persistent=truecatches up. If the instance was stopped at 03:30, the job runs once as soon as the timer starts again. It only works withOnCalendar=timers.- No pile-ups. If last night's run is still going when the timer fires, systemd leaves it running instead of starting a second copy.
- The clock is UTC. EC2 instances use UTC unless you change it with
sudo timedatectl set-timezone Europe/Berlin. Runtimedatectlbefore you trust "03:30".
To keep a classic crontab instead, install it with sudo dnf install cronie, start it with sudo systemctl enable --now crond, then use crontab -e as usual. The cron to systemd timer converter turns an existing crontab line into both unit files.
The trade-off is the instance: you pay for it around the clock, it is a single point of failure, and a timer on a hand-built server disappears when the server is replaced, so keep the unit files in your image or user data. A scheduler library inside an always-on app has a related problem: with three replicas, all three fire the job unless you add a lock.
How EventBridge Scheduler works
EventBridge Scheduler is AWS's managed clock. A schedule stores when to run, which API to call and the IAM role to call it with. It can reach more than 270 AWS services and over 6,000 API operations; for periodic jobs, four matter.
Every schedule needs an expression, a flexible time window setting (Off counts, but you must give one) and a target with an execution role. In the EventBridge console, choose Schedules under Scheduler, then Create schedule. Lambda and Step Functions are under Templated targets; for ECS and Batch, choose All APIs and search for RunTask or SubmitJob. The Settings page holds Schedule state, Action after schedule completion, the Retry policy, the Dead-letter queue (DLQ) and Permissions. In code, the resource is AWS::Scheduler::Schedule in CloudFormation, and the AWS CDK has stable Schedule and ScheduleGroup constructs in aws-cdk-lib/aws-scheduler, with targets in aws-cdk-lib/aws-scheduler-targets.
The execution role
Scheduler assumes this role on every call. The console can create it; for the CLI, CloudFormation or an SDK you create it yourself. AWS recommends limiting the trust policy to your account and a schedule group:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "scheduler.amazonaws.com" },
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "111122223333",
"aws:SourceArn": "arn:aws:scheduler:eu-central-1:111122223333:schedule-group/jobs"
}
}
}
]
}
aws:SourceArn must name a schedule group, never a single schedule. Create the group with aws scheduler create-schedule-group --name jobs. Then allow the one action the target needs, scoped to that resource: lambda:InvokeFunction, ecs:RunTask, batch:SubmitJob or states:StartExecution. The job keeps its own, separate role for what it touches.
Scheduled rules are now legacy
Older tutorials create EventBridge rules with a schedule pattern, often under the old name CloudWatch Events. AWS now labels these scheduled rules as legacy and recommends Scheduler for new schedules. Existing rules keep running.
| EventBridge Scheduler | Scheduled rules (legacy) | |
|---|---|---|
| Time zone | Any IANA time zone, daylight saving handled | UTC only |
| Expressions | cron(), rate() and one-time at() | cron() and rate() |
| Flexible time window | Yes | No |
| Targets | More than 6,000 API operations | Event bus targets, including HTTPS API destinations |
| Retries and DLQ | Per schedule | Per target |
| Where it lives | Schedule groups | The default event bus only |
Schedule expressions and time zones
Scheduler takes three expression types: cron() for set times, rate() for a fixed interval and at() for a single run.
cron(30 3 * * ? *)
rate(15 minutes)
at(2026-12-01T09:00:00)
AWS cron has six fields: minutes, hours, day-of-month, month, day-of-week and year. Day-of-month and day-of-week can't both be set: if one holds a value or *, the other must be ?. A line copied from a crontab fails as it is.
| Schedule | Unix crontab | AWS |
|---|---|---|
| Every day at 03:30 | 30 3 * * * | cron(30 3 * * ? *) |
| Every 15 minutes | */15 * * * * | cron(0/15 * * * ? *) |
| Weekdays at 18:00 | 0 18 * * 1-5 | cron(0 18 ? * MON-FRI *) |
| Mondays at 09:30 | 30 9 * * 1 | cron(30 9 ? * MON *) |
| Last day of the month at 23:00 | No L in standard cron | cron(0 23 L * ? *) |
Watch out
Weekday numbers differ. In AWS cron, 1 is Sunday and 2 is Monday; in a Unix crontab, 1 is Monday. Use names such as MON or MON-FRI and the problem disappears. The Unix, Quartz and AWS cron converter translates expressions in both directions.
Rate or cron?
A rate schedule without a start date starts when you create it, so a daily rate fires at whatever time you clicked Create schedule, and it counts a day as 24 hours, so a daylight saving change moves it by an hour. Use rate() when any minute will do and cron() when the time of day matters: rate(15 minutes) runs four times an hour, but only cron(0/15 * * * ? *) runs on the quarter hour.
Time zones and daylight saving
Give cron and one-time schedules an IANA time zone such as Europe/Berlin (--schedule-expression-timezone in the CLI); without one they run in UTC. Scheduler then follows that zone's daylight saving rules:
- Spring forward: a time that doesn't exist that day is skipped. In Berlin, clocks jump from 02:00 to 03:00, so a 02:30 job doesn't run that night.
- Fall back: a time that happens twice runs once, at the second occurrence.
That is why the examples here use 03:30: if every night counts, avoid the hour your zone's clocks change. Cron, time zones and daylight saving time covers the general problem.
Flexible time windows
With the window Off, the target runs at the scheduled minute. A flexible window of 1 to 1,440 minutes lets Scheduler start it any time within that many minutes after, which spreads load when many jobs share a minute. Keep it Off for anything a person expects at a fixed time.
Pick the target
Lambda: short jobs
A standard Lambda function stops at its timeout, at most 900 seconds (15 minutes); functions on Lambda Managed Instances allow up to 90 minutes for asynchronous invocations. If a run can get close, move it to a container before the first timeout.
Scheduler invokes Lambda asynchronously: its job is done once Lambda accepts the event, and if the function then fails, Lambda's own retries apply, two more attempts by default. You can also add the schedule from the function's Add trigger menu (Scheduler). Payloads, IAM and deployment are in the Lambda scheduling guide.
ECS on Fargate: a container per run
The ECS target calls RunTask: the target ARN is the cluster, and EcsParameters names the task definition, launch type and network. You pay only while the task runs, so it suits jobs that outgrow Lambda or already ship as a container image. Check three things first:
- Networking. A Fargate task needs a route to pull its image: a public IP in a public subnet, a NAT gateway in a private subnet, or Amazon ECR interface VPC endpoints.
AssignPublicIpcan only beENABLEDwith theFARGATElaunch type. - Permissions. The execution role needs
ecs:RunTaskplusiam:PassRolefor the task's execution role and task role. - Exit. The task stops when its main process exits; a process that hangs keeps it, and the bill, running.
One image can serve several jobs, because each schedule's input can override the container command. Save the target as target.json:
{
"Arn": "arn:aws:ecs:eu-central-1:111122223333:cluster/jobs",
"RoleArn": "arn:aws:iam::111122223333:role/scheduler-jobs",
"EcsParameters": {
"TaskDefinitionArn": "arn:aws:ecs:eu-central-1:111122223333:task-definition/jobs:7",
"LaunchType": "FARGATE",
"NetworkConfiguration": {
"awsvpcConfiguration": {
"Subnets": ["subnet-0123456789abcdef0"],
"SecurityGroups": ["sg-0123456789abcdef0"],
"AssignPublicIp": "DISABLED"
}
}
},
"Input": "{\"containerOverrides\": [{\"name\": \"app\", \"command\": [\"python\", \"jobs/nightly_report.py\"]}]}",
"RetryPolicy": { "MaximumRetryAttempts": 2, "MaximumEventAgeInSeconds": 3600 },
"DeadLetterConfig": { "Arn": "arn:aws:sqs:eu-central-1:111122223333:scheduler-dlq" }
}
Then create the schedule:
aws scheduler create-schedule \
--name nightly-report \
--group-name jobs \
--schedule-expression "cron(30 3 * * ? *)" \
--schedule-expression-timezone "Europe/Berlin" \
--flexible-time-window '{"Mode": "OFF"}' \
--target file://target.json
Note the lowercase awsvpcConfiguration, which is the key Scheduler expects. The container name must match the task definition, and the command is a list of arguments, not one string with spaces.
AWS Batch: heavy or queued work
Batch adds job queues and managed compute environments, which pays off for data processing, many vCPUs, GPUs or array jobs, and is overhead for a five-second clean-up.
Scheduler reaches Batch through a universal target: the target ARN is arn:aws:scheduler:::aws-sdk:batch:submitJob and the input is the SubmitJob request. Parameter names must be PascalCase, not the camelCase shown in the Batch API reference:
{
"JobName": "my-scheduled-job",
"JobQueue": "my-job-queue",
"JobDefinition": "my-job-definition"
}
Scheduler does not validate a universal target's input when you create the schedule, so a typo becomes a failure on every run. Scope batch:SubmitJob to the job queue and job definition, and confirm runs on the Batch console's Jobs page: Scheduler only knows it submitted the job. For SageMaker training jobs queued in Batch, target SubmitServiceJob instead.
Step Functions: several steps, each with its own retry
When a job is really extract, transform and notify, schedule a state machine with the StartExecution templated target instead of writing retry logic into one script. Standard workflows run for up to a year and execute exactly once; Express workflows stop at five minutes and, started asynchronously, run at least once. For scheduled work, Standard is the usual choice.
Test a schedule without waiting
Test the job first on its own: invoke the function or run the task with the same input the schedule will send. Then test the wiring with a one-time schedule a few minutes ahead that deletes itself after it runs:
aws scheduler create-schedule \
--name nightly-report-test \
--group-name jobs \
--schedule-expression "at(2026-11-18T09:05:00)" \
--schedule-expression-timezone "Europe/Berlin" \
--action-after-completion DELETE \
--flexible-time-window '{"Mode": "OFF"}' \
--target file://target.json
Don't move the production schedule to "now" and plan to change it back. One-time schedules that stay behind after running still count against your quota, which is another reason to set DELETE.
Retries, dead-letter queues and duplicate runs
When the call to the target fails, Scheduler retries with exponential backoff until it reaches the limits in the retry policy: up to 185 retries, within a maximum event age you set between one minute and 24 hours. After that the invocation goes to the dead-letter queue, which must be a standard SQS queue (FIFO queues are not supported). Without one, it is dropped and only the InvocationDroppedCount metric records it. The DLQ message carries the target's ERROR_CODE and ERROR_MESSAGE, which usually name the problem.
These retries cover delivery only. Whether the job did its work, only its own logs can tell.
Tip
Alarm on TargetErrorCount and InvocationDroppedCount in the AWS/Scheduler namespace, and on messages arriving in the DLQ. A dead-letter queue nobody watches is the same as no dead-letter queue.
Delivery is at least once, and a job can run twice for three reasons: a Scheduler retry, a Lambda retry after a function error, or a person starting it by hand. Make every job safe to repeat:
- Claim work before doing it. An
UPDATE … SET status = 'processing' WHERE status = 'pending'leaves nothing for a second run to do. - Key each run on its scheduled time. Put
<aws.scheduler.scheduled-time>in the input, for example{"run_for": "<aws.scheduler.scheduled-time>"}. Scheduler replaces it with the time the run was scheduled for, so a retry carries the same value. - Use idempotency keys on payments, e-mails and webhooks, so the provider drops the duplicate.
- Record the last successful run. A stale timestamp catches what no metric shows: the job that never ran. See monitoring cron jobs.
Cost, limits and clean-up
Prices as of November 2026, from AWS's pricing pages:
- EventBridge Scheduler: 14 million invocations a month are free, counted across all Regions; AWS's pricing example charges $1.00 per million beyond that. A job every minute is 44,640 invocations in a 31-day month.
- Lambda: the free tier covers 1 million requests and 400,000 GB-seconds a month. Beyond it you pay $0.20 per million requests plus duration, billed per millisecond.
- Fargate: vCPU and memory per second, from the start of the image download until the task stops, with a one-minute minimum (five minutes for Windows containers).
- AWS Batch: no charge of its own; you pay for the instances or Fargate tasks it launches.
- Step Functions: Standard workflows per state transition, Express workflows per execution, duration and memory.
- EC2: the instance bills while it runs, whether a job is running or not.
Scheduler's default limits, most of them adjustable: 10 million schedules per Region, 500 schedule groups, and 1,000 invocations per second in the largest Regions (500 in the others). Above that rate invocations are delayed, not dropped. A target's input can be up to 256 KB, and a schedule name up to 64 letters, digits, hyphens, underscores and periods.
Clean-up
A recurring schedule keeps calling its target until you delete it or its end date passes, and deleting it does not stop a Batch job or task that is already running. Deleting a schedule group deletes every schedule in it. Give test schedules an end date, and remove the roles, queues and images you created for them.
Calling an HTTPS endpoint instead
Sometimes the job already lives behind a URL: a route in the app on your EC2 instance, or an API Gateway route in front of a function. Then something just has to call that URL on time, with a secret only the caller knows.
Scheduler can't, because its targets are AWS API operations. The AWS-native route is an EventBridge API destination as the target of a scheduled rule; its connection keeps Basic, API key or OAuth credentials in Secrets Manager. But scheduled rules run in UTC only, and an API destination gives up after 5 seconds and retries, so a slow endpoint runs twice unless it answers quickly and works in the background.
An external HTTP scheduler skips the AWS setup. With Cronit, for example:
- Make the endpoint reject requests without a secret header, such as
X-Cron-Secretwith a long random value, and return as soon as the work has started. - In Cronit, create a job with method POST, your URL, that header, the schedule
30 3 * * *and the time zone Europe/Berlin. The preview shows the schedule in plain English and how many runs a month it makes. - Send the test request before saving. From then on every run appears in the job's execution log with its status, and a job that keeps failing switches itself off.
Note the five fields: Cronit uses standard cron syntax, not AWS's six. Plans and their monthly run allowances are in the pricing section.
When a schedule misbehaves
| Symptom | Likely cause | Check first |
|---|---|---|
| Never ran | Schedule disabled; wrong Region; trust policy names a different schedule group | The schedule's state and group, and the role's trust policy |
| Ran, but did nothing | Error in the job; Fargate task could not pull its image; universal target input in the wrong case | Target logs, the DLQ's ERROR_CODE |
| Ran twice | A Scheduler or Lambda retry on a job that is not idempotent; an API destination timeout | The job's own run log and the scheduled time of each run |
| Ran at the wrong time | No time zone, so UTC; a rate counting from creation; a flexible window; a daylight saving skip | Time zone, start date, window |
| Stopped running | End date passed; an update reset settings; the group was deleted | aws scheduler get-schedule --name nightly-report --group-name jobs |
For a crontab or timer on EC2, the cron job not running checklist covers paths, environment variables and permissions.
FAQ
- Can EventBridge Scheduler run a job every 30 seconds?
- No. The smallest unit is a minute, and every schedule type invokes its target with 60-second precision: a run due at 01:00 starts somewhere between 01:00:00 and 01:00:59. For work that must happen more often, keep a long-running ECS task or service that loops on its own timer.
- Do I have to migrate my existing EventBridge scheduled rules?
- No. AWS labels them legacy, but existing rules keep working. Move a rule when you need a time zone, a one-time run or a flexible window: create the new schedule, confirm its first run, then disable the rule so the job does not run twice.
- Why can't I see CloudWatch metrics for a single schedule?
- EventBridge Scheduler publishes its metrics with one dimension, the schedule group. To alarm on one important job by itself, give it its own group, or have the job log a start and finish line that you can alarm on.
- How do I pause a schedule without deleting it?
- Set its state to DISABLED, in the console or with
aws scheduler update-schedule --state DISABLED. An update replaces the whole schedule and resets any optional setting you leave out, so runget-schedulefirst and pass every setting again.