Skip to content

GetMetricStatistics

Source: src/AWS/CloudWatch/GetMetricStatistics.ts

Runtime binding for cloudwatch:GetMetricStatistics — fetch aggregated datapoints for a single metric (the older single-metric query API; prefer GetMetricData for metric math or multi-metric queries).

Provide CloudWatch.GetMetricStatisticsHttp on the hosting Lambda Function to satisfy the requirement.

// init — grants cloudwatch:GetMetricStatistics
const getMetricStatistics = yield* AWS.CloudWatch.GetMetricStatistics();
// runtime
const now = yield* Effect.sync(() => Date.now());
const result = yield* getMetricStatistics({
Namespace: "MyApp/Payments",
MetricName: "PaymentProcessed",
StartTime: new Date(now - 3_600_000),
EndTime: new Date(now),
Period: 60,
Statistics: ["Sum"],
});
const datapoints = result.Datapoints ?? [];