Commit e2aa338
authored
feat(cloudwatch): anomaly detection alarms (#31232)
### Issue #10540
Closes #10540.
### Reason for this change
This change adds proper support for creating CloudWatch anomaly detection alarms, fixing a long-standing issue where alarms using anomaly detection with range-based comparison operators would fail at deployment time with the error:
ComparisonOperators for ranges require ThresholdMetricId to be set (Service: AmazonCloudWatch; Status Code: 400; Error
Code: ValidationError)
### Description of changes
1. **New `AnomalyDetectionAlarm` class**: a dedicated class for anomaly detection alarms that handles all the complexity of setting up the anomaly detection band and configuring the alarm correctly.
2. **Enhanced helper methods**: Added the `anomalyDetectionFor` helper method on `Metric` class to handle the creation of the MathExpression wrapper using the function `ANOMALY_DETECTION_BAND`.
3. **Improved validation**: Added proper validation to ensure users don't mix standard alarm operators with anomaly detection metrics or vice versa.
### Description of how you validated changes
- Added comprehensive unit tests for the new `AnomalyDetectionAlarm` class
- Executed the integration test (`packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.anomaly-detection-alarm.ts`) on a test account
### Checklist
- [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*1 parent 67c8e5a commit e2aa338
File tree
33 files changed
+32599
-776
lines changed- packages
- @aws-cdk-testing/framework-integ/test
- aws-cloudwatch/test
- integ.anomaly-detection-alarm.js.snapshot
- asset.97484721f29e34bf38d7a459804dd2d2a8dea6f8c27d7531e215bf4274fbc895.bundle
- integ.math-alarm-and-dashboard.js.snapshot
- aws-dynamodb/test/integ.dynamodb.alarm-metrics.js.snapshot
- aws-cdk-lib
- aws-cloudwatch
- lib
- private
- test
- core/lib
33 files changed
+32599
-776
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments