diff --git a/packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts b/packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts index fc863f8f37870..99f7a27bc138c 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts @@ -625,7 +625,7 @@ export class MathExpression implements IMetric { const missingIdentifiers = allIdentifiersInExpression(this.expression).filter(i => !this.usingMetrics[i]); const warnings: { [id: string]: string } = {}; - if (!this.expression.toUpperCase().match('\\s*SELECT|SEARCH|METRICS\\s.*') && missingIdentifiers.length > 0) { + if (!this.expression.toUpperCase().match('\\s*INSIGHT_RULE_METRIC|SELECT|SEARCH|METRICS\\s.*') && missingIdentifiers.length > 0) { warnings['CloudWatch:Math:UnknownIdentifier'] = `Math expression '${this.expression}' references unknown identifiers: ${missingIdentifiers.join(', ')}. Please add them to the 'usingMetrics' map.`; } diff --git a/packages/aws-cdk-lib/aws-cloudwatch/test/metric-math.test.ts b/packages/aws-cdk-lib/aws-cloudwatch/test/metric-math.test.ts index 38d2bbd934a52..3b73f4193ddde 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/test/metric-math.test.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/test/metric-math.test.ts @@ -100,6 +100,15 @@ describe('Metric Math', () => { expect(m.warningsV2).toBeUndefined(); }); + test('metrics INSIGHT_RULE_METRIC expression does not produce warning for unknown identifier', () => { + const m = new MathExpression({ + expression: "INSIGHT_RULE_METRIC('RejectedConnectionsRule', 'Sum')", + usingMetrics: {}, + }); + + expect(m.warningsV2).toBeUndefined(); + }); + test('math expression referring to unknown expressions produces a warning, even when nested', () => { const m = new MathExpression({ expression: 'e1 + 5',