aws-cdk: cli: synth fails if cdk.out does not exist
š Bug Report
What is the problem?
cdk synth returns ENOENT: no such file or directory, open 'cdk.out/manifest.json' when the cdk.out directory is not present.
However, this results in the creation of a default manifest.json, and subsequent calls to synth succeed
Reproduction Steps
from cdk project directory:
- mvn clean
- rm -rf cdk.out
- mvn compile
- cdk synth
Verbose Log
xxxxxxxxx:cdk xxxxxxxx$ ls
cdk.json cdk.out pom.xml src target
xxxxxxxxx:cdk xxxxxxxx$ mvn clean
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.xxx.xxx:project >--------------------
[INFO] Building project 0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ project ---
[INFO] Deleting /Users/xxxxxxxx/workspace/xxxxxxxx/cdk/target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.303 s
[INFO] Finished at: 2019-08-19T16:27:07-07:00
[INFO] ------------------------------------------------------------------------
xxxxxxxxx:cdk xxxxxxxx$ rm -rf cdk.out
xxxxxxxxx:cdk xxxxxxxx$ mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.xxx.xxx:project >--------------------
[INFO] Building project 0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/xxxxxxxx/workspace/xxxxxxxx/cdk/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ project ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /Users/xxxxxxxx/workspace/xxxxxxxx/cdk/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.835 s
[INFO] Finished at: 2019-08-19T16:27:24-07:00
[INFO] ------------------------------------------------------------------------
xxxxxxxxx:cdk xxxxxxxx$ cdk synth
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.xxx.xxx:project >--------------------
[INFO] Building project 0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) @ project ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.574 s
[INFO] Finished at: 2019-08-19T16:27:31-07:00
[INFO] ------------------------------------------------------------------------
ENOENT: no such file or directory, open 'cdk.out/manifest.json'
Environment
- CDK CLI Version: 1.4.0 (build 175471f)
- Module Version:
- OS: OSX Mojave
- Language: Java
Other information
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 13
- Comments: 16 (5 by maintainers)
Commits related to this issue
- chore: formalize that `App`s `outdir` property should not be used If this property is passed it has to agree with the CLI's `--output` flag. If this property is not passed, it will default to the CL... — committed to aws/aws-cdk by rix0rrr 3 years ago
- docs: note that `App`s `outdir` property should not be used (#16670) If this property is passed it has to agree with the CLI's `--output` flag. If this property is not passed, it will default to t... — committed to aws/aws-cdk by rix0rrr 3 years ago
- docs: note that `App`s `outdir` property should not be used (#16670) If this property is passed it has to agree with the CLI's `--output` flag. If this property is not passed, it will default to t... — committed to TikiTDO/aws-cdk by rix0rrr 3 years ago
Thanks to @ivoanjo who also had this problem, Iām able to reproduce this in Java.
I was able to reproduce this using our standard sample-app package from
cdk init -l=javaand modify the code to dropapp.synth(). Runningcdk synthon this when thereās nocdk.out/folder gets this error.There seems to be some race condition between the
cdk.out/folder being generated and when the CLI expects it to be present for parsing. This specifically happens when the app does not callapp.synth().For those encountering this issue, the workaround is for your app to call
app.synth()at the end of the program.For me the issue was that I had missed the difference between the file in
binand the file inlib, so I was missing:As soon as I added that back in I stopped getting the error about the missing file. Itād be great if we could improve the error message in this case.
I was getting the same error.
Code:
However, after adding
app.synth();to the end of my main method:I then got the expected output when running
cdk synth:So check that you have
app.synth()after your resource definitions. Iām not sure why this worked for me, I havenāt done a deeper dive than this (because it now works for me) but wanted to share.Hope this is helpful in some way.
Hereās the offending block in the
aws-cdkpacakge: https://github.com/aws/aws-cdk/blob/5a6fa7fa17a5dce5e429eed4ebfe2dbbac3d6d07/packages/aws-cdk/lib/api/cxapp/exec.ts#L68-L92The code looks for
outputon the command line and disregards theAppProps.outdirpassed in code. That means in order to resolve this, you have to set bothoutdirin theAppPropsduring instantiation of theApp, as well as use--outdirset to the same exact value, or completely rely on--output. Any way you go,--outputis required. This is very redundant, and makes using dynamic output directories a massive pain. Not remotely ideal.@rix0rrr @shivlaks @SomayaB Thereās the triage. Can we get a fix or some documentation around this?
I donāt think setting
AppProps.outdircan even work, as the CLI wonāt know where to look for the Cloud Assembly.Now that you mention it, Iām not sure why we have that property in the first place. I guess it is for unit tests.
@eladb you added this property in https://github.com/aws/aws-cdk/pull/2636⦠do you happen to remember why it is configurable from inside the CDK app?
I am having the same problem. However, the cause of the problem seems to differ in that in my case, it occurs whenever I specify an outdir other than cdk.out, whether or not I call app.synth().
I created a separate issue for this (#5815), since I think the cause is different. But the relevant details from that issue are copied below.
If I synthesize without a modified outdir (producing a cdk.out/mainfest.json), and then synthesize with a modified outdir, it successfully outputs the expected files to the modified outdir. So it seems that at some point during the process it needs to read from cdk.out/manifest.json, whether or not the outdir property is set to cdk.out, and then it proceeds to behave as expected.
It also appears that a cdk.out folder is created when running cdk synth with a modified outdir.
Additionally, it seems that in at least one project where I am having this issue, running ācdk deployā deploys the templates in cdk.out, not the specified outdir. So it seems like currently the outdir is just not really useful.
Is it possible that ācdk.outā is hard-coded somewhere?