aws-samples / aws-cdk-examples

Example projects using the AWS CDK
Apache License 2.0
5.08k stars 2.14k forks source link

https://github.com/aws-samples/aws-cdk-examples/tree/master/java/static-site is not working #751

Open nagkumar opened 2 years ago

nagkumar commented 2 years ago

Describe the bug

env variables are correct, but still gives error

Expected Behavior

this example should work locally

Current Behavior

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.1.0:java (default-cli) on project static-site: An exception occurred while executing the Java class. Error: Cannot retrieve value from context provider hosted-zone since account/region are not specified at the stack level. Configure "env" with an account and region when you define your stack.See https://docs.aws.amazon.com/cdk/latest/guide/environments.html for more details. [ERROR] @jsii/kernel.RuntimeError: Error: Cannot retrieve value from context provider hosted-zone since account/region are not specified at the stack level. Configure "env" with an account and region when you define your stack.See https://docs.aws.amazon.com/cdk/latest/guide/environments.html for more details. [ERROR] at Kernel._ensureSync (C:\Users\RAJANA~1\AppData\Local\Temp\jsii-java-runtime14064205540975823778\lib\program.js:7889:27) [ERROR] at Kernel.sinvoke (C:\Users\RAJANA~1\AppData\Local\Temp\jsii-java-runtime14064205540975823778\lib\program.js:7325:34) [ERROR] at KernelHost.processRequest (C:\Users\RAJANA~1\AppData\Local\Temp\jsii-java-runtime14064205540975823778\lib\program.js:10466:36) [ERROR] at KernelHost.run (C:\Users\RAJANA~1\AppData\Local\Temp\jsii-java-runtime14064205540975823778\lib\program.js:10429:22) [ERROR] at Immediate._onImmediate (C:\Users\RAJANA~1\AppData\Local\Temp\jsii-java-runtime14064205540975823778\lib\program.js:10430:46) [ERROR] at process.processImmediate (node:internal/timers:471:21)

Reproduction Steps

cdk ls

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.43.1 (build c1ebb85)

Framework Version

No response

Node.js Version

nod 18

OS

win 10

Language

Java

Language Version

18

liyanone commented 1 year ago

Able to reproduce the issue by running below commands mvn compile cdk ls cdk bootstrap cdk deploy -c domain=mystaticsite.com -c subdomain=www --all

Actually, this is considered an warning which only occurs when running cdk synth/deploy/destroy. It DOES NOT block the cdk process as there are default region/account values set in example code or local aws configure.

As suggested in the warning log itself as well as in another issue (https://github.com/aws-samples/aws-cdk-examples/issues/238), follow this guide (https://docs.aws.amazon.com/cdk/v2/guide/environments.html) to set the account and region env in your code.