1import type * as ECS from "@distilled.cloud/aws/ecs";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { Cluster } from "./Cluster.ts";
5
6export interface ExecuteCommandRequest extends Omit<
7 ECS.ExecuteCommandRequest,
8 "cluster"
9> {}
10
11/**
12 * Runtime binding for `ecs:ExecuteCommand` (ECS Exec).
13 *
14 * Bind this operation to a `Cluster` inside a function runtime to get a
15 * callable that starts a command against a running container in the bound
16 * cluster. The cluster ARN is injected automatically and the host is granted
17 * `ecs:ExecuteCommand` on the cluster and its tasks.
18 *
19 * The target task must have been launched with `enableExecuteCommand` and the
20 * task role must allow the SSM messages channel. The response's
21 * `session.tokenValue` is a `Redacted` bearer token for the SSM WebSocket
22 * stream (`session.streamUrl`).
23 * ### Executing Commands
24 * **Example:** Run a Command in a Container
25 * ```typescript
26 * const executeCommand = yield* AWS.ECS.ExecuteCommand(cluster);
27 *
28 * const response = yield* executeCommand({
29 * task: taskArn,
30 * command: "ls -al /",
31 * interactive: true,
32 * });
33 * const streamUrl = response.session?.streamUrl;
34 * ```
35 *
36 * @binding
37 */
38export interface ExecuteCommand extends Binding.Service<
39 ExecuteCommand,
40 "AWS.ECS.ExecuteCommand",
41 (
42 cluster: Cluster,
43 ) => Effect.Effect<
44 (
45 request: ExecuteCommandRequest,
46 ) => Effect.Effect<ECS.ExecuteCommandResponse, ECS.ExecuteCommandError>
47 >
48> {}
49export const ExecuteCommand = Binding.Service<ExecuteCommand>(
50 "AWS.ECS.ExecuteCommand",
51);