Alarm
Source:
src/AWS/CloudWatch/Alarm.ts
A CloudWatch metric alarm — watches a single metric (or metric-math
expression) and transitions between OK, ALARM, and
INSUFFICIENT_DATA, optionally firing actions on state change.
Creating Alarms
Section titled “Creating Alarms”Threshold Alarm
const alarm = yield* Alarm("HighErrors", { MetricName: "Errors", Namespace: "AWS/Lambda", Statistic: "Sum", Period: 60, EvaluationPeriods: 1, Threshold: 1, ComparisonOperator: "GreaterThanOrEqualToThreshold",});Alarm on a Lambda Function’s Errors
const fn = yield* MyFunction;
const alarm = yield* Alarm("FnErrors", { MetricName: "Errors", Namespace: "AWS/Lambda", Dimensions: [{ Name: "FunctionName", Value: fn.functionName }], Statistic: "Sum", Period: 60, EvaluationPeriods: 1, Threshold: 1, ComparisonOperator: "GreaterThanOrEqualToThreshold", TreatMissingData: "notBreaching",});Reading Alarm State at Runtime
Section titled “Reading Alarm State at Runtime”// init — bind the alarm to the function (see DescribeAlarms)const describeAlarms = yield* AWS.CloudWatch.DescribeAlarms(alarm);
// runtimeconst result = yield* describeAlarms();const state = result.MetricAlarms?.[0]?.StateValue;