CreateSchedule
Source:
src/AWS/Scheduler/CreateSchedule.ts
Runtime binding for scheduler:CreateSchedule — THE dynamic-scheduling
pattern (per-user reminders, delayed callbacks): a deployed Lambda mints
one-shot at(...) or recurring schedules at runtime.
The binding is constructed with the schedule execution role (the IAM
role EventBridge Scheduler assumes to invoke the target) and, optionally, a
ScheduleGroup that scopes which schedules the host may create. At deploy
time it contributes BOTH scheduler:CreateSchedule on the group’s schedule
ARN pattern AND iam:PassRole on the execution role — without the PassRole
statement schedule creation fails only at runtime.
Creating Schedules At Runtime
Section titled “Creating Schedules At Runtime”Mint A One-Shot Schedule From A Lambda
// deploy time: pre-create the execution role Scheduler will assumeconst role = yield* AWS.IAM.Role("ReminderRole", { assumeRolePolicyDocument: { Version: "2012-10-17", Statement: [ { Effect: "Allow", Principal: { Service: "scheduler.amazonaws.com" }, Action: ["sts:AssumeRole"], }, ], }, inlinePolicies: { SendReminder: { Version: "2012-10-17", Statement: [ { Effect: "Allow", Action: ["sqs:SendMessage"], Resource: [queue.queueArn], }, ], }, },});const createSchedule = yield* AWS.Scheduler.CreateSchedule(role);
// runtime: schedule a one-shot delivery in 15 minutesconst queueArn = yield* queue.queueArn;yield* createSchedule({ Name: `reminder-${userId}`, ScheduleExpression: "at(2026-01-01T00:00:00)", ActionAfterCompletion: "DELETE", Target: { Arn: yield* queueArn, Input: JSON.stringify({ userId }), },});Scope Creation To A Schedule Group
const group = yield* AWS.Scheduler.ScheduleGroup("Reminders", {});const createSchedule = yield* AWS.Scheduler.CreateSchedule(role, group);// runtime calls create schedules inside the group only