| 1 | import type * as mwaa from "@distilled.cloud/aws/mwaa"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { AirflowRoleOptions } from "./BindingHttp.ts"; |
| 5 | import type { Environment } from "./Environment.ts"; |
| 6 | |
| 7 | export interface InvokeRestApiRequest extends Omit< |
| 8 | mwaa.InvokeRestApiRequest, |
| 9 | "Name" |
| 10 | > {} |
| 11 | |
| 12 | /** |
| 13 | * Runtime binding for `airflow:InvokeRestApi` (Airflow 2.4.3+). |
| 14 | * |
| 15 | * Bind an {@link Environment} inside a function runtime to call the Apache |
| 16 | * Airflow REST API on the environment's webserver — trigger DAG runs, list |
| 17 | * DAGs, inspect task instances, manage variables and connections — without |
| 18 | * minting tokens yourself. The IAM grant is scoped to the Airflow RBAC role |
| 19 | * the call is mapped to (`Admin` by default — pass `{ airflowRole }` to |
| 20 | * scope it down). Provide the implementation with |
| 21 | * `Effect.provide(AWS.MWAA.InvokeRestApiHttp)`. |
| 22 | * ### Invoking the Airflow REST API |
| 23 | * **Example:** List DAGs |
| 24 | * ```typescript |
| 25 | * // init — bind the operation to the environment |
| 26 | * const invokeRestApi = yield* AWS.MWAA.InvokeRestApi(environment); |
| 27 | * |
| 28 | * // runtime — GET /dags through the Airflow REST API |
| 29 | * const result = yield* invokeRestApi({ |
| 30 | * Method: "GET", |
| 31 | * Path: "/dags", |
| 32 | * QueryParameters: { paused: false }, |
| 33 | * }); |
| 34 | * const dags = result.RestApiResponse as { dags: { dag_id: string }[] }; |
| 35 | * ``` |
| 36 | * |
| 37 | * **Example:** Trigger a DAG Run |
| 38 | * ```typescript |
| 39 | * const run = yield* invokeRestApi({ |
| 40 | * Method: "POST", |
| 41 | * Path: "/dags/my_dag/dagRuns", |
| 42 | * Body: { conf: { source: "lambda" } }, |
| 43 | * }); |
| 44 | * ``` |
| 45 | * |
| 46 | * @binding |
| 47 | */ |
| 48 | export interface InvokeRestApi extends Binding.Service< |
| 49 | InvokeRestApi, |
| 50 | "AWS.MWAA.InvokeRestApi", |
| 51 | ( |
| 52 | environment: Environment, |
| 53 | options?: AirflowRoleOptions, |
| 54 | ) => Effect.Effect< |
| 55 | ( |
| 56 | request: InvokeRestApiRequest, |
| 57 | ) => Effect.Effect<mwaa.InvokeRestApiResponse, mwaa.InvokeRestApiError> |
| 58 | > |
| 59 | > {} |
| 60 | |
| 61 | export const InvokeRestApi = Binding.Service<InvokeRestApi>( |
| 62 | "AWS.MWAA.InvokeRestApi", |
| 63 | ); |