diff --git a/packages/@aws-cdk/aws-cloudwatch/lib/private/env-tokens.ts b/packages/@aws-cdk/aws-cloudwatch/lib/private/env-tokens.ts index e0157393df489..15fcda4886791 100644 --- a/packages/@aws-cdk/aws-cloudwatch/lib/private/env-tokens.ts +++ b/packages/@aws-cdk/aws-cloudwatch/lib/private/env-tokens.ts @@ -26,7 +26,9 @@ class StackDependentToken implements cdk.IResolvable { public resolve(context: cdk.IResolveContext) { const stackValue = this.fn(cdk.Stack.of(context.scope)); - if (cdk.Token.isUnresolved(stackValue) || stackValue === this.originalValue) { + // Don't render if the values are definitely the same. If the stack + // is unresolved we don't know, better output the value. + if (!cdk.Token.isUnresolved(stackValue) && stackValue === this.originalValue) { return undefined; } diff --git a/packages/@aws-cdk/aws-cloudwatch/test/test.cross-environment.ts b/packages/@aws-cdk/aws-cloudwatch/test/test.cross-environment.ts index a35f34d953304..3a970d80bb20e 100644 --- a/packages/@aws-cdk/aws-cloudwatch/test/test.cross-environment.ts +++ b/packages/@aws-cdk/aws-cloudwatch/test/test.cross-environment.ts @@ -46,6 +46,38 @@ export = { test.done(); }, + + 'metric with explicit account and region will render in environment agnostic stack'(test: Test) { + // GIVEN + const graph = new GraphWidget({ + left: [ + a.with({ account: '1234', region: 'us-north-5' }) + ], + }); + + // THEN + graphMetricsAre(test, new Stack(), graph, [ + [ 'Test', 'ACount', { accountId: '1234', region: 'us-north-5' }], + ]); + + test.done(); + }, + + 'metric attached to agnostic stack will not render in agnostic stack'(test: Test) { + // GIVEN + const graph = new GraphWidget({ + left: [ + a.attachTo(new Stack()), + ], + }); + + // THEN + graphMetricsAre(test, new Stack(), graph, [ + [ 'Test', 'ACount' ], + ]); + + test.done(); + }, }, 'in alarms': {