| 1 | import type * as ec2 from "@distilled.cloud/aws/ec2"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Volume } from "./Volume.ts"; |
| 5 | |
| 6 | /** |
| 7 | * `CreateSnapshot` request with `VolumeId` injected from the bound |
| 8 | * {@link Volume}. |
| 9 | */ |
| 10 | export interface CreateSnapshotRequest extends Omit< |
| 11 | ec2.CreateSnapshotRequest, |
| 12 | "VolumeId" |
| 13 | > {} |
| 14 | |
| 15 | /** |
| 16 | * Runtime binding for the `CreateSnapshot` operation scoped to the bound |
| 17 | * {@link Volume} (IAM actions `ec2:CreateSnapshot` + `ec2:CreateTags` on the |
| 18 | * volume ARN and the region-wide snapshot wildcard — snapshot creation |
| 19 | * authorizes against both the source volume and the new snapshot). |
| 20 | * |
| 21 | * Creates a point-in-time EBS snapshot of the volume — e.g. a Lambda that |
| 22 | * takes an application-consistent backup before a risky migration. The |
| 23 | * snapshot is created `pending` and completes asynchronously. Provide the |
| 24 | * implementation with `Effect.provide(AWS.EC2.CreateSnapshotHttp)`. |
| 25 | * ### Volume Backups |
| 26 | * **Example:** Snapshot the bound volume |
| 27 | * ```typescript |
| 28 | * // init — bind the operation to the volume |
| 29 | * const createSnapshot = yield* AWS.EC2.CreateSnapshot(volume); |
| 30 | * |
| 31 | * // runtime — take a point-in-time backup |
| 32 | * const snapshot = yield* createSnapshot({ |
| 33 | * Description: "pre-migration backup", |
| 34 | * }); |
| 35 | * console.log(snapshot.SnapshotId, snapshot.State); |
| 36 | * ``` |
| 37 | * |
| 38 | * @binding |
| 39 | */ |
| 40 | export interface CreateSnapshot extends Binding.Service< |
| 41 | CreateSnapshot, |
| 42 | "AWS.EC2.CreateSnapshot", |
| 43 | ( |
| 44 | volume: Volume, |
| 45 | ) => Effect.Effect< |
| 46 | ( |
| 47 | request?: CreateSnapshotRequest, |
| 48 | ) => Effect.Effect<ec2.Snapshot, ec2.CreateSnapshotError> |
| 49 | > |
| 50 | > {} |
| 51 | |
| 52 | export const CreateSnapshot = Binding.Service<CreateSnapshot>( |
| 53 | "AWS.EC2.CreateSnapshot", |
| 54 | ); |