| 1 | import * as cloudwatch from "@distilled.cloud/aws/cloudwatch"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | |
| 5 | export interface GetMetricStatisticsRequest |
| 6 | extends cloudwatch.GetMetricStatisticsInput {} |
| 7 | |
| 8 | /** |
| 9 | * Runtime binding for `cloudwatch:GetMetricStatistics` — fetch aggregated |
| 10 | * datapoints for a single metric (the older single-metric query API; |
| 11 | * prefer {@link GetMetricData} for metric math or multi-metric queries). |
| 12 | * |
| 13 | * Provide `CloudWatch.GetMetricStatisticsHttp` on the hosting Lambda |
| 14 | * Function to satisfy the requirement. |
| 15 | * ### Querying Metrics |
| 16 | * **Example:** Fetch Hourly Sums for a Metric |
| 17 | * ```typescript |
| 18 | * // init — grants cloudwatch:GetMetricStatistics |
| 19 | * const getMetricStatistics = yield* AWS.CloudWatch.GetMetricStatistics(); |
| 20 | * |
| 21 | * // runtime |
| 22 | * const now = yield* Effect.sync(() => Date.now()); |
| 23 | * const result = yield* getMetricStatistics({ |
| 24 | * Namespace: "MyApp/Payments", |
| 25 | * MetricName: "PaymentProcessed", |
| 26 | * StartTime: new Date(now - 3_600_000), |
| 27 | * EndTime: new Date(now), |
| 28 | * Period: 60, |
| 29 | * Statistics: ["Sum"], |
| 30 | * }); |
| 31 | * const datapoints = result.Datapoints ?? []; |
| 32 | * ``` |
| 33 | * |
| 34 | * @binding |
| 35 | */ |
| 36 | export interface GetMetricStatistics extends Binding.Service< |
| 37 | GetMetricStatistics, |
| 38 | "AWS.CloudWatch.GetMetricStatistics", |
| 39 | () => Effect.Effect< |
| 40 | ( |
| 41 | request: GetMetricStatisticsRequest, |
| 42 | ) => Effect.Effect< |
| 43 | cloudwatch.GetMetricStatisticsOutput, |
| 44 | cloudwatch.GetMetricStatisticsError |
| 45 | > |
| 46 | > |
| 47 | > {} |
| 48 | |
| 49 | export const GetMetricStatistics = Binding.Service<GetMetricStatistics>( |
| 50 | "AWS.CloudWatch.GetMetricStatistics", |
| 51 | ); |