Skip to content

New serverless pattern - eventbridge-scheduler-cron-migration - #3570

Open
rextheking wants to merge 1 commit into
aws-samples:mainfrom
rextheking:rextheking-feature-eventbridge-scheduler-cron-migration
Open

rextheking wants to merge 1 commit into
aws-samples:mainfrom
rextheking:rextheking-feature-eventbridge-scheduler-cron-migration

Conversation

@rextheking

@rextheking rextheking commented Dec 4, 2026 •

Copy link
Copy Markdown

Submission issue: #3571

What this adds

A pattern for migrating cron on a VM to Amazon EventBridge Scheduler, rather than wiring up a single schedule.

An import script reads an existing crontab (or a schedule.json), converts each entry, and creates one schedule per line targeting a single Lambda dispatcher. The dispatcher records every run in a DynamoDB table keyed on the scheduled window, publishes a completion metric, and a CloudWatch alarm with TreatMissingData: breaching fires when a job does not report completion. A catch-up function replays windows missed while no schedule was running, for example during a deployment, idempotently.

Why a new family rather than a variant

The repo asks contributors to add a variant to an existing family when the services match, so here is the reasoning in case you would rather I move it.

There are 65 pattern folders with schedule or scheduler in the name, and I went through the closest ones. eventbridge-schedule-to-lambda (10 variants), eventbridge-schedule-to-lambda-dlq/python/sam, eventbridge-schedule-lambda-to-dynamodb/dotnet/cdk, lambda-durable-eventbridge-cron and lambda-durable-scheduled-tasks all wire up one schedule and invoke a target. None of them imports a crontab, keeps run history, alarms on a missing completion, or replays a missed window. Searching the repo for crontab, catch-up and run-history returns no pattern content at all.

The closest service match is eventbridge-schedule-lambda-to-dynamodb, and I am happy to move this under it as python/sam if you prefer. I kept it separate because the pattern is about the migration, and because the folder name is what someone searching for how to replace cron will actually find. If you would rather it live in the existing family, say so and I will move it in this PR.

Scope

Four services (EventBridge Scheduler, Lambda, DynamoDB, CloudWatch) and two Lambda functions. I deliberately kept this smaller than it could have been: one dispatcher with the example jobs as functions inside it rather than one Lambda function per job, and the crontab importer as a local script rather than deployed infrastructure. Happy to trim further if it reads as too much for a pattern.

Verified

Deployed to my own account in us-east-1, tested, and torn down.

  • The recurring cron(0 * * * ? *) schedule fired on its own and invoked the dispatcher 21 seconds into its window, inside the documented 60 second precision.
  • Run history held the run#<scheduled-time> item and the marker, with the execution ID and schedule ARN substituted by Scheduler.
  • Re-running the same window returned SKIPPED; the conditional write refused the duplicate.
  • The alarm reached ALARM with "1 missing datapoint was treated as [Breaching]".
  • Catch-up listed the correct missed windows in UTC for a schedule defined in America/New_York (02:00 New York resolved to 07:00Z).
  • ActionAfterCompletion=DELETE removed the one-time catch-up schedule after it fired.
  • Re-running the import updated the existing schedules in place.
  • sam validate --lint, sam build, node _scripts/validate.js and node _scripts/check-folder.js all pass.
  • cd tools && python3 -m unittest test_cron_to_scheduler covers 28 known-answer conversions, 12 refusals and the field-count and ? invariants.

Three things that look odd but are deliberate

The Scheduler trust policy scopes aws:SourceArn to the schedule group, not to the schedules. Scoping it to schedule/<group>/* makes CreateSchedule fail with "The execution role you provide must allow AWS EventBridge Scheduler to assume the role". The User Guide's confused deputy page calls this out: the ARN must be a schedule group. I hit this during testing and left a comment in the template so the next person does not.

scheduler:ListSchedules is granted on schedule/*/* while GetSchedule is scoped to the group. ListSchedules is authorised against schedule/*/* even when the call filters by GroupName, so it cannot be scoped to one group. Also found during testing, also commented.

The one-time catch-up schedule is created through the API, not in template.yaml. AWS::Scheduler::Schedule has no ActionAfterCompletion property, and the quotas page notes that the schedule count includes completed one-time schedules. Creating it through the API with ActionAfterCompletion=DELETE lets it clean itself up.

Notes

  • No architecture diagram, per the publishing guidelines.
  • The README names Python rather than a runtime version; the version lives in template.yaml.
  • The importer needs boto3 to create schedules, but --dry-run converts and checks a crontab with no dependencies, which is the part worth running first.

Adds eventbridge-scheduler-cron-migration/python/sam: migrating cron on a VM
to Amazon EventBridge Scheduler.

An import script converts a crontab into one schedule per entry targeting a
Lambda dispatcher, each run is recorded in DynamoDB keyed on the scheduled
window, a CloudWatch alarm treats a missing completion as breaching, and a
catch-up function idempotently replays windows missed during a deployment.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants