| 1 | import type * as autoscaling from "@distilled.cloud/aws/auto-scaling"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { AutoScalingGroup } from "./AutoScalingGroup.ts"; |
| 5 | |
| 6 | /** |
| 7 | * `EnterStandby` request with `AutoScalingGroupName` injected from the bound |
| 8 | * {@link AutoScalingGroup}. |
| 9 | */ |
| 10 | export interface EnterStandbyRequest extends Omit< |
| 11 | autoscaling.EnterStandbyQuery, |
| 12 | "AutoScalingGroupName" |
| 13 | > {} |
| 14 | |
| 15 | /** |
| 16 | * `ExitStandby` request with `AutoScalingGroupName` injected from the bound |
| 17 | * {@link AutoScalingGroup}. |
| 18 | */ |
| 19 | export interface ExitStandbyRequest extends Omit< |
| 20 | autoscaling.ExitStandbyQuery, |
| 21 | "AutoScalingGroupName" |
| 22 | > {} |
| 23 | |
| 24 | export interface StandbyClient { |
| 25 | /** |
| 26 | * Move instances into `Standby` — they stay attached (and optionally keep |
| 27 | * counting toward desired capacity) but receive no load balancer traffic. |
| 28 | */ |
| 29 | enter: ( |
| 30 | request: EnterStandbyRequest, |
| 31 | ) => Effect.Effect< |
| 32 | autoscaling.EnterStandbyAnswer, |
| 33 | autoscaling.EnterStandbyError |
| 34 | >; |
| 35 | /** |
| 36 | * Move standby instances back into service; the desired capacity is |
| 37 | * incremented accordingly. |
| 38 | */ |
| 39 | exit: ( |
| 40 | request: ExitStandbyRequest, |
| 41 | ) => Effect.Effect< |
| 42 | autoscaling.ExitStandbyAnswer, |
| 43 | autoscaling.ExitStandbyError |
| 44 | >; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Runtime binding for the `EnterStandby` / `ExitStandby` operations (IAM |
| 49 | * actions `autoscaling:EnterStandby` and `autoscaling:ExitStandby` scoped to |
| 50 | * the group ARN). |
| 51 | * |
| 52 | * Temporarily pulls instances out of service — to debug a misbehaving |
| 53 | * instance, apply a patch, or drain it during maintenance — and puts them |
| 54 | * back afterwards. Provide the implementation with |
| 55 | * `Effect.provide(AWS.AutoScaling.StandbyHttp)`. |
| 56 | * ### Standby Maintenance |
| 57 | * **Example:** Pull an instance for maintenance, then return it |
| 58 | * ```typescript |
| 59 | * // init — bind the operations to the group |
| 60 | * const standby = yield* AWS.AutoScaling.Standby(group); |
| 61 | * |
| 62 | * // runtime — take the instance out of rotation |
| 63 | * yield* standby.enter({ |
| 64 | * InstanceIds: [instanceId], |
| 65 | * ShouldDecrementDesiredCapacity: true, |
| 66 | * }); |
| 67 | * |
| 68 | * // ... perform maintenance ... |
| 69 | * |
| 70 | * // runtime — put it back in service |
| 71 | * yield* standby.exit({ InstanceIds: [instanceId] }); |
| 72 | * ``` |
| 73 | * |
| 74 | * @binding |
| 75 | */ |
| 76 | export interface Standby extends Binding.Service< |
| 77 | Standby, |
| 78 | "AWS.AutoScaling.Standby", |
| 79 | (group: AutoScalingGroup) => Effect.Effect<StandbyClient> |
| 80 | > {} |
| 81 | |
| 82 | export const Standby = Binding.Service<Standby>("AWS.AutoScaling.Standby"); |