Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot retrieve value from context provider hosted-zone since account/region are not specified at the stack leve #238

Closed
kbroughton opened this issue Feb 3, 2020 · 12 comments
Assignees
Labels
bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. guidance Question that needs advice or information.

Comments

@kbroughton
Copy link

🐛 Bug Report

Need more instructions in readme.
First, you need to import modules via npm or yarn.
Then, need to get region and account into context.

What is the problem?

cdk deploy causes errors.

Reproduction Steps

aws-cdk-examples/typescript/static-site> cdk synth -c domain=x.com -c subdomain=y
l. 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)

I've defined the CDK_ variables in the shell.

Verbose Log

aws-cdk-examples/typescript/static-site/node_modules/@aws-cdk/core/lib/context-provider.js:41
throw new Error(Cannot retrieve value from context provider ${options.provider} since account/region +
^

Error: Cannot retrieve value from context provider hosted-zone 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)
at Function.getValue (/aws-cdk-examples/typescript/static-site/node_modules/@aws-cdk/core/lib/context-provider.js:41:19)
at Function.fromLookup (
/aws-cdk-examples/typescript/static-site/node_modules/@aws-cdk/aws-route53/lib/hosted-zone.js:71:49)
at new StaticSite (/aws-cdk-examples/typescript/static-site/static-site.js:21:41)
at new MyStaticSiteStack (
/aws-cdk-examples/typescript/static-site/index.js:20:9)
at Object. (~/aws-cdk-examples/typescript/static-site/index.js:27:1)
at Module._compile (internal/modules/cjs/loader.js:734:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
at Module.load (internal/modules/cjs/loader.js:626:32)
at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
at Function.Module._load (internal/modules/cjs/loader.js:558:3)
Subprocess exited with error 1

Environment

  • CDK CLI Version: 1.22.0 (build 309ac1b)
  • Example: typescript/static-site
  • Example Version: 1.0.0
  • OS: OSX Mojave
  • Language: TypeScript

Other information

@kbroughton kbroughton added the bug This issue is a bug. label Feb 3, 2020
@iamhopaul123
Copy link
Contributor

@kbroughton I think it is because you don't have the default profile in your aws config file. Can you run aws configure to see if it fixes the problem?

@kbroughton
Copy link
Author

I do have ~/.aws/config and ~/.aws/credentials [default] blocks defined.

e.g. for config.
[default]
region = us-east-1
output = json

I use the keys regularly. I also tried explicitly setting CDK_ vars on the CLI - no luck.
aws configure does not set a "default account" either.

@iamhopaul123
Copy link
Contributor

Here's the guidance that is relevant to your issue. Does this help solve your issue?

@SomayaB SomayaB added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 4, 2020
@SomayaB SomayaB self-assigned this Feb 4, 2020
@SomayaB SomayaB added the guidance Question that needs advice or information. label Feb 4, 2020
@StraightOuttaCrompton
Copy link

StraightOuttaCrompton commented Feb 7, 2020

I also experienced this issue receiving the message

Cannot retrieve value from context provider hosted-zone 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)

I was puzzled when setting the environment variables and getting the same error. It took me a while to figure out I had to do the following

new MyDevStack(app, 'dev', { 
  env: { 
    account: process.env.CDK_DEFAULT_ACCOUNT, 
    region: process.env.CDK_DEFAULT_REGION 
}});

as outlined in the guidance provided by @iamhopaul123

@SomayaB SomayaB removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 10, 2020
@SomayaB
Copy link
Contributor

SomayaB commented Feb 10, 2020

Thanks @iamhopaul123 and @StraightOuttaCrompton! @kbroughton does that solve your issue?

@SomayaB SomayaB added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. closing-soon This issue will automatically close in 4 days unless further comments are made. and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Feb 10, 2020
@SomayaB
Copy link
Contributor

SomayaB commented Feb 17, 2020

Closing this issue since a solution seems to have been found. Feel free to reopen.

@SomayaB SomayaB closed this as completed Feb 17, 2020
@amilnayar92
Copy link

@iamhopaul123 I am still facing this issue even after providing the env. This error only happens when i use nested stacks. For normal stack it works fine! Using cdk 1.38.0

@iamhopaul123
Copy link
Contributor

@amilnayar92 can you open another issue and provide more details about the issue you have?

@amilnayar92
Copy link

@iamhopaul123 Two issues open with same errors: aws/aws-cdk#5547 and aws/aws-cdk#4651

@iamhopaul123
Copy link
Contributor

@amilnayar92 oh seems like it is a route53 problem. HostedZone.fromLookup just doesn't work for nested stack. We probably are not able to solve it on our end but glad to be informed about the existence of this issue!

@evayde
Copy link

evayde commented Dec 24, 2020

@iamhopaul123 You've saved me a quintillion hours of debugging. Thanks.

@dillonharlessCORE
Copy link

@amilnayar92 oh seems like it is a route53 problem. HostedZone.fromLookup just doesn't work for nested stack. We probably are not able to solve it on our end but glad to be informed about the existence of this issue!

Really? I feel like this throws a pretty big wrench in the ideal that you can "keep your infrastructure and app code in the same repository", per the AWS CDK best practices document on AWS's website...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

7 participants