| 1 | import type * as budgets from "@distilled.cloud/aws/budgets"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Budget } from "./Budget.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Request for {@link DescribeBudget} — the bound budget's `AccountId` and |
| 8 | * `BudgetName` are injected automatically. |
| 9 | */ |
| 10 | export interface DescribeBudgetRequest extends Omit< |
| 11 | budgets.DescribeBudgetRequest, |
| 12 | "AccountId" | "BudgetName" |
| 13 | > {} |
| 14 | |
| 15 | /** |
| 16 | * Runtime binding for `budgets:ViewBudget` via `DescribeBudget`. |
| 17 | * |
| 18 | * Bind this operation to a {@link Budget} to read its definition and — most |
| 19 | * usefully at runtime — its `CalculatedSpend` (actual and forecasted spend so |
| 20 | * far in the period), e.g. for a cost kill-switch or a spend dashboard. |
| 21 | * Provide the implementation with |
| 22 | * `Effect.provide(AWS.Budgets.DescribeBudgetHttp)`. |
| 23 | * ### Reading Budget Spend |
| 24 | * **Example:** Check Actual Spend Against the Limit |
| 25 | * ```typescript |
| 26 | * // init — bind the operation to the budget |
| 27 | * const describeBudget = yield* AWS.Budgets.DescribeBudget(budget); |
| 28 | * |
| 29 | * // runtime |
| 30 | * const { Budget: b } = yield* describeBudget(); |
| 31 | * const actual = Number(b?.CalculatedSpend?.ActualSpend?.Amount ?? "0"); |
| 32 | * const limit = Number(b?.BudgetLimit?.Amount ?? "0"); |
| 33 | * const overBudget = limit > 0 && actual >= limit; |
| 34 | * ``` |
| 35 | * |
| 36 | * @binding |
| 37 | */ |
| 38 | export interface DescribeBudget extends Binding.Service< |
| 39 | DescribeBudget, |
| 40 | "AWS.Budgets.DescribeBudget", |
| 41 | ( |
| 42 | budget: Budget, |
| 43 | ) => Effect.Effect< |
| 44 | ( |
| 45 | request?: DescribeBudgetRequest, |
| 46 | ) => Effect.Effect< |
| 47 | budgets.DescribeBudgetResponse, |
| 48 | budgets.DescribeBudgetError |
| 49 | > |
| 50 | > |
| 51 | > {} |
| 52 | |
| 53 | export const DescribeBudget = Binding.Service<DescribeBudget>( |
| 54 | "AWS.Budgets.DescribeBudget", |
| 55 | ); |