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

main
ts 60 lines 1.9 KB
Raw
1 import type * as ECS from "@distilled.cloud/aws/ecs";
2 import * as Binding from "alchemy/Binding";
3 import type * as Effect from "effect/Effect";
4 import type { Cluster } from "./Cluster.ts";
5 import type { Task } from "./Task.ts";
6
7 export interface RunTaskRequest extends Omit<ECS.RunTaskRequest, "cluster" | "taskDefinition"> {}
8
9 /**
10 * Runtime binding for `ecs:RunTask`.
11 *
12 * Bind this operation to a `Cluster` and `Task` inside a function runtime to
13 * get a callable that starts a Fargate task from the bound task
14 * definition. The cluster and task definition ARNs are injected automatically;
15 * the host is granted `ecs:RunTask` on the task definition plus `iam:PassRole`
16 * on the task and execution roles.
17 * ### Running Tasks
18 * **Example:** Launch a Fargate Task from a handler
19 * ```typescript
20 * const api = yield* AWS.Lambda.Function(
21 * "Api",
22 * { main: import.meta.url, functionUrl: true },
23 * Effect.gen(function* () {
24 * // init: bind the launch (IAM grants happen here)
25 * const runTask = yield* AWS.ECS.RunTask(cluster, task);
26 *
27 * return {
28 * fetch: Effect.gen(function* () {
29 * // runtime: launch a task per request
30 * const response = yield* runTask({
31 * launchType: "FARGATE",
32 * networkConfiguration: {
33 * awsvpcConfiguration: {
34 * subnets: [subnetId],
35 * assignPublicIp: "ENABLED",
36 * },
37 * },
38 * });
39 * return yield* HttpServerResponse.json({
40 * taskArn: response.tasks?.[0]?.taskArn,
41 * });
42 * }),
43 * };
44 * }),
45 * );
46 * ```
47 *
48 * @binding
49 */
50 export interface RunTask extends Binding.Service<
51 RunTask,
52 "AWS.ECS.RunTask",
53 (
54 cluster: Cluster,
55 task: Task,
56 ) => Effect.Effect<
57 (request: RunTaskRequest) => Effect.Effect<ECS.RunTaskResponse, ECS.RunTaskError>
58 >
59 > {}
60 export const RunTask = Binding.Service<RunTask>("AWS.ECS.RunTask");