diff --git a/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts b/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts index 078671e301b4e..4af8c66342cbb 100644 --- a/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts +++ b/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts @@ -68,6 +68,15 @@ export interface AlarmProps { * @default true */ actionsEnabled?: boolean; + + /** + * The number of datapoints that must be breaching to trigger the alarm. This is used only if you are setting an "M + * out of N" alarm. In that case, this value is the M. For more information, see Evaluating an Alarm in the Amazon + * CloudWatch User Guide. + * + * @default ``evaluationPeriods`` + */ + datapointsToAlarm?: number; } /** @@ -153,6 +162,7 @@ export class Alarm extends Construct { // Evaluation comparisonOperator, threshold: props.threshold, + datapointsToAlarm: props.datapointsToAlarm, evaluateLowSampleCountPercentile: props.evaluateLowSampleCountPercentile, evaluationPeriods: props.evaluationPeriods, treatMissingData: props.treatMissingData, diff --git a/packages/@aws-cdk/aws-cloudwatch/lib/metric.ts b/packages/@aws-cdk/aws-cloudwatch/lib/metric.ts index d3a5bc9b5d4e7..5f037b1561ffc 100644 --- a/packages/@aws-cdk/aws-cloudwatch/lib/metric.ts +++ b/packages/@aws-cdk/aws-cloudwatch/lib/metric.ts @@ -157,6 +157,7 @@ export class Metric { alarmName: props.alarmName, alarmDescription: props.alarmDescription, comparisonOperator: props.comparisonOperator, + datapointsToAlarm: props.datapointsToAlarm, threshold: props.threshold, evaluationPeriods: props.evaluationPeriods, evaluateLowSampleCountPercentile: props.evaluateLowSampleCountPercentile, @@ -372,6 +373,15 @@ export interface NewAlarmProps { * @default true */ actionsEnabled?: boolean; + + /** + * The number of datapoints that must be breaching to trigger the alarm. This is used only if you are setting an "M + * out of N" alarm. In that case, this value is the M. For more information, see Evaluating an Alarm in the Amazon + * CloudWatch User Guide. + * + * @default ``evaluationPeriods`` + */ + datapointsToAlarm?: number; } function ifUndefined(x: T | undefined, def: T | undefined): T | undefined { diff --git a/packages/@aws-cdk/aws-cloudwatch/test/integ.alarm-and-dashboard.expected.json b/packages/@aws-cdk/aws-cloudwatch/test/integ.alarm-and-dashboard.expected.json index bc6a19679b430..2a0b5888788c6 100644 --- a/packages/@aws-cdk/aws-cloudwatch/test/integ.alarm-and-dashboard.expected.json +++ b/packages/@aws-cdk/aws-cloudwatch/test/integ.alarm-and-dashboard.expected.json @@ -8,10 +8,8 @@ "Properties": { "ComparisonOperator": "GreaterThanOrEqualToThreshold", "EvaluationPeriods": 3, - "MetricName": "ApproximateNumberOfMessagesVisible", - "Namespace": "AWS/SQS", - "Period": 300, "Threshold": 100, + "DatapointsToAlarm": 2, "Dimensions": [ { "Name": "QueueName", @@ -23,6 +21,9 @@ } } ], + "MetricName": "ApproximateNumberOfMessagesVisible", + "Namespace": "AWS/SQS", + "Period": 300, "Statistic": "Average" } }, diff --git a/packages/@aws-cdk/aws-cloudwatch/test/integ.alarm-and-dashboard.ts b/packages/@aws-cdk/aws-cloudwatch/test/integ.alarm-and-dashboard.ts index 33e45b97c1b19..ac6944251406b 100644 --- a/packages/@aws-cdk/aws-cloudwatch/test/integ.alarm-and-dashboard.ts +++ b/packages/@aws-cdk/aws-cloudwatch/test/integ.alarm-and-dashboard.ts @@ -21,7 +21,8 @@ const metric = new cloudwatch.Metric({ const alarm = metric.newAlarm(stack, 'Alarm', { threshold: 100, - evaluationPeriods: 3 + evaluationPeriods: 3, + datapointsToAlarm: 2, }); const dashboard = new cloudwatch.Dashboard(stack, 'Dash'); diff --git a/packages/@aws-cdk/aws-cloudwatch/test/test.alarm.ts b/packages/@aws-cdk/aws-cloudwatch/test/test.alarm.ts index b2dac59fbe3c5..ad5a11edd36da 100644 --- a/packages/@aws-cdk/aws-cloudwatch/test/test.alarm.ts +++ b/packages/@aws-cdk/aws-cloudwatch/test/test.alarm.ts @@ -17,13 +17,15 @@ export = { new Alarm(stack, 'Alarm', { metric: testMetric, threshold: 1000, - evaluationPeriods: 2 + evaluationPeriods: 3, + datapointsToAlarm: 2, }); // THEN expect(stack).to(haveResource('AWS::CloudWatch::Alarm', { ComparisonOperator: "GreaterThanOrEqualToThreshold", - EvaluationPeriods: 2, + EvaluationPeriods: 3, + DatapointsToAlarm: 2, MetricName: "Metric", Namespace: "CDK/Test", Period: 300,