| 1 | import type * as emr from "@distilled.cloud/aws/emr-serverless"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Application } from "./Application.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Request accepted by the {@link StartJobRun} runtime callable. The |
| 8 | * `applicationId` is injected from the bound {@link Application}; the |
| 9 | * idempotency `clientToken` is auto-generated when omitted. |
| 10 | */ |
| 11 | export type StartJobRunInput = Omit< |
| 12 | emr.StartJobRunRequest, |
| 13 | "applicationId" | "clientToken" |
| 14 | > & { |
| 15 | /** |
| 16 | * Idempotency token deduplicating retried submissions. |
| 17 | * @default a generated UUID per call |
| 18 | */ |
| 19 | clientToken?: string; |
| 20 | }; |
| 21 | |
| 22 | /** |
| 23 | * Runtime binding for `emr-serverless:StartJobRun`. |
| 24 | * |
| 25 | * Submits a Spark or Hive job to the bound {@link Application} — the |
| 26 | * serverless equivalent of `spark-submit`. The application id is injected |
| 27 | * from the binding; the caller supplies the job driver, the execution role |
| 28 | * the job assumes, and optional configuration overrides. Grants |
| 29 | * `iam:PassRole` (conditioned to `emr-serverless.amazonaws.com`) so the |
| 30 | * function can hand the service the execution role. Provide the |
| 31 | * implementation with `Effect.provide(AWS.EMRServerless.StartJobRunHttp)`. |
| 32 | * ### Running Jobs |
| 33 | * **Example:** Submit A Spark Job |
| 34 | * ```typescript |
| 35 | * // init — bind the operation to the application |
| 36 | * const startJobRun = yield* AWS.EMRServerless.StartJobRun(app); |
| 37 | * |
| 38 | * // runtime |
| 39 | * const run = yield* startJobRun({ |
| 40 | * executionRoleArn: jobRoleArn, |
| 41 | * jobDriver: { |
| 42 | * sparkSubmit: { |
| 43 | * entryPoint: "s3://my-scripts/etl.py", |
| 44 | * entryPointArguments: ["--date", "2026-07-14"], |
| 45 | * }, |
| 46 | * }, |
| 47 | * executionTimeoutMinutes: 60, |
| 48 | * }); |
| 49 | * yield* Effect.log(`started ${run.jobRunId}`); |
| 50 | * ``` |
| 51 | * |
| 52 | * @binding |
| 53 | */ |
| 54 | export interface StartJobRun extends Binding.Service< |
| 55 | StartJobRun, |
| 56 | "AWS.EMRServerless.StartJobRun", |
| 57 | ( |
| 58 | application: Application, |
| 59 | ) => Effect.Effect< |
| 60 | ( |
| 61 | request: StartJobRunInput, |
| 62 | ) => Effect.Effect<emr.StartJobRunResponse, emr.StartJobRunError> |
| 63 | > |
| 64 | > {} |
| 65 | export const StartJobRun = Binding.Service<StartJobRun>( |
| 66 | "AWS.EMRServerless.StartJobRun", |
| 67 | ); |