Skip to content

Commit

Permalink
fix(core): improve context providers error message for env-agnostic s…
Browse files Browse the repository at this point in the history
…tacks (#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
  • Loading branch information
Elad Ben-Israel authored Jul 1, 2019
1 parent a20c841 commit 5b80146
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/@aws-cdk/core/lib/context-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5b80146

Please sign in to comment.