From 5b80146beaf73f64457272141709a1482c6a2211 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 1 Jul 2019 11:31:52 +0300 Subject: [PATCH] fix(core): improve context providers error message for env-agnostic stacks (#3137) Following up on #2922: improve the error message emitted when trying to read context from an environment-agnostic stack by calling out CDK_DEFAULT_ACCOUNT and CDK_DEFAULT_REGION as a way to inherit environment information from the CLI. Fixes #3078 Fixes #3120 Fixes #3130 --- packages/@aws-cdk/core/lib/context-provider.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/core/lib/context-provider.ts b/packages/@aws-cdk/core/lib/context-provider.ts index 4353218580111..cd211e02638e8 100644 --- a/packages/@aws-cdk/core/lib/context-provider.ts +++ b/packages/@aws-cdk/core/lib/context-provider.ts @@ -71,7 +71,10 @@ export class ContextProvider { const stack = Stack.of(scope); if (Token.isUnresolved(stack.account) || Token.isUnresolved(stack.region)) { - throw new Error(`Cannot retrieve value from context provider ${options.provider} since account/region are not specified at the stack level`); + throw new Error(`Cannot retrieve value from context provider ${options.provider} since account/region ` + + `are not specified at the stack level. Either configure "env" with explicit account and region when ` + + `you define your stack, or use the environment variables "CDK_DEFAULT_ACCOUNT" and "CDK_DEFAULT_REGION" ` + + `to inherit environment information from the CLI (not recommended for production stacks)`); } const { key, props } = this.getKey(scope, options);