The best way to control Claude Code, Codex and more from any computer or phone

main
ts 110 lines 3.63 KB
Raw
1 import type * as scheduler from "@distilled.cloud/aws/scheduler";
2 import * as Binding from "alchemy/Binding";
3 import type * as Effect from "effect/Effect";
4 import type { Role } from "../IAM/Role.ts";
5 import type { ScheduleGroup } from "./ScheduleGroup.ts";
6
7 /**
8 * The schedule target passed at runtime. `RoleArn` defaults to the execution
9 * role the binding was constructed with, so callers normally omit it.
10 */
11 export interface CreateScheduleTarget extends Omit<scheduler.Target, "RoleArn"> {
12 /**
13 * Execution role EventBridge Scheduler assumes to invoke the target.
14 * @default the execution role bound via `CreateSchedule(role)`
15 */
16 RoleArn?: string;
17 }
18
19 export interface CreateScheduleRequest extends Omit<
20 scheduler.CreateScheduleInput,
21 "GroupName" | "Target" | "FlexibleTimeWindow"
22 > {
23 /**
24 * Target the schedule invokes when it fires. The bound execution role is
25 * injected as `RoleArn` unless the request overrides it.
26 */
27 Target: CreateScheduleTarget;
28 /**
29 * Flexible time window configuration.
30 * @default { Mode: "OFF" }
31 */
32 FlexibleTimeWindow?: scheduler.FlexibleTimeWindow;
33 }
34
35 /**
36 * Runtime binding for `scheduler:CreateSchedule` — THE dynamic-scheduling
37 * pattern (per-user reminders, delayed callbacks): a deployed Lambda mints
38 * one-shot `at(...)` or recurring schedules at runtime.
39 *
40 * The binding is constructed with the schedule **execution role** (the IAM
41 * role EventBridge Scheduler assumes to invoke the target) and, optionally, a
42 * `ScheduleGroup` that scopes which schedules the host may create. At deploy
43 * time it contributes BOTH `scheduler:CreateSchedule` on the group's schedule
44 * ARN pattern AND `iam:PassRole` on the execution role — without the PassRole
45 * statement schedule creation fails only at runtime.
46 * ### Creating Schedules At Runtime
47 * **Example:** Mint A One-Shot Schedule From A Lambda
48 * ```typescript
49 * // deploy time: pre-create the execution role Scheduler will assume
50 * const role = yield* AWS.IAM.Role("ReminderRole", {
51 * assumeRolePolicyDocument: {
52 * Version: "2012-10-17",
53 * Statement: [
54 * {
55 * Effect: "Allow",
56 * Principal: { Service: "scheduler.amazonaws.com" },
57 * Action: ["sts:AssumeRole"],
58 * },
59 * ],
60 * },
61 * inlinePolicies: {
62 * SendReminder: {
63 * Version: "2012-10-17",
64 * Statement: [
65 * {
66 * Effect: "Allow",
67 * Action: ["sqs:SendMessage"],
68 * Resource: [queue.queueArn],
69 * },
70 * ],
71 * },
72 * },
73 * });
74 * const createSchedule = yield* AWS.Scheduler.CreateSchedule(role);
75 *
76 * // runtime: schedule a one-shot delivery in 15 minutes
77 * const queueArn = yield* queue.queueArn;
78 * yield* createSchedule({
79 * Name: `reminder-${userId}`,
80 * ScheduleExpression: "at(2026-01-01T00:00:00)",
81 * ActionAfterCompletion: "DELETE",
82 * Target: {
83 * Arn: yield* queueArn,
84 * Input: JSON.stringify({ userId }),
85 * },
86 * });
87 * ```
88 *
89 * **Example:** Scope Creation To A Schedule Group
90 * ```typescript
91 * const group = yield* AWS.Scheduler.ScheduleGroup("Reminders", {});
92 * const createSchedule = yield* AWS.Scheduler.CreateSchedule(role, group);
93 * // runtime calls create schedules inside the group only
94 * ```
95 *
96 * @binding
97 */
98 export interface CreateSchedule extends Binding.Service<
99 CreateSchedule,
100 "AWS.Scheduler.CreateSchedule",
101 <R extends Role>(
102 executionRole: R,
103 group?: ScheduleGroup,
104 ) => Effect.Effect<
105 (
106 request: CreateScheduleRequest,
107 ) => Effect.Effect<scheduler.CreateScheduleOutput, scheduler.CreateScheduleError>
108 >
109 > {}
110 export const CreateSchedule = Binding.Service<CreateSchedule>("AWS.Scheduler.CreateSchedule");