Skip to content

Commit 5b80146

Browse files
author
Elad Ben-Israel
authored
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
1 parent a20c841 commit 5b80146

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/@aws-cdk/core/lib/context-provider.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ export class ContextProvider {
7171
const stack = Stack.of(scope);
7272

7373
if (Token.isUnresolved(stack.account) || Token.isUnresolved(stack.region)) {
74-
throw new Error(`Cannot retrieve value from context provider ${options.provider} since account/region are not specified at the stack level`);
74+
throw new Error(`Cannot retrieve value from context provider ${options.provider} since account/region ` +
75+
`are not specified at the stack level. Either configure "env" with explicit account and region when ` +
76+
`you define your stack, or use the environment variables "CDK_DEFAULT_ACCOUNT" and "CDK_DEFAULT_REGION" ` +
77+
`to inherit environment information from the CLI (not recommended for production stacks)`);
7578
}
7679

7780
const { key, props } = this.getKey(scope, options);

0 commit comments

Comments
 (0)