I'm trying to create an anomaly detection on a math expression, removing several layers of abstraction. I have a CustomMetricWithAnomalyDetection as shown below:
I could have missed a few keys here and there but the general idea is that I have a math expression for which I'd like to enable anomaly detection. However, during deployment, CloudFormation gives me an error, indicating:
Resource handler returned message: "Threshold metric expression must use ANOMALY_DETECTION_BAND function
Looking at the generated template, I found that the ThresholdMetricId seems to be set incorrectly:
Version
5.4.2
Steps and/or minimal code example to reproduce
I'm trying to create an anomaly detection on a math expression, removing several layers of abstraction. I have a
CustomMetricWithAnomalyDetection
as shown below:I could have missed a few keys here and there but the general idea is that I have a math expression for which I'd like to enable anomaly detection. However, during deployment, CloudFormation gives me an error, indicating:
Looking at the generated template, I found that the
ThresholdMetricId
seems to be set incorrectly:The correct
ThresholdMetricId
should beexpr_1
, but it is currently set toalarm_39eb6b24e4ab
.Expected behavior
ThresholdMetricId
should beexpr_1
since that's the expression that has the anomaly detection defined.Actual behavior
ThresholdMetricId
isalarm_39eb6b24e4ab
instead.Other details
Looking at the code https://github.com/cdklabs/cdk-monitoring-constructs/blob/465e388bf1418160143959ec18e2781f97fcae72/lib/common/metric/AnomalyDetectionMathExpression.ts#L37-L44
I think the problem is that it is assuming the last metric is always the anomaly detection expression which is clearly not true in this case.