aws-cdk: (cdk pipelines): primary output directory `root/cdk.out` generates errors since notices release
What is the problem?
We observe in the default cdk pipeline:
Failed to load notices from cache: Error: ENOENT: no such file or directory, open '/root/.cdk/cache/notices.json'
Error on request: Error: read ETIMEDOUT
Notices refreshed
Error on request: Error: read ETIMEDOUT
Failed to get tree.json file: Error: cdk.out/tree.json: ENOTDIR: not a directory, open 'cdk.out/tree.json'
Note, we have the cdk root of our project in <project root>/infrastructure folder. That is specified in code:
primaryOutputDirectory: "infrastructure/cdk.out",
It does not result in error, just in a very long wait and then succesful exit.
Reproduction Steps
const pipeline = new pipelines.CodePipeline(
this,
"niceName",
{
pipelineName: "niceName",
crossAccountKeys: true,
synth: new pipelines.CodeBuildStep("SynthStep", {
input: remote,
commands: [
"cd infrastructure",
"npm ci",
"npm run test",
"npm run build",
"npx cdk synth",
],
primaryOutputDirectory: "infrastructure/cdk.out",
}),
codeBuildDefaults: {
vpc: <...>,
subnetSelection: { subnets: <...> },
partialBuildSpec: codebuild.BuildSpec.fromObject({
phases: {
install: {
"runtime-versions": {
nodejs: "14.x",
},
},
pre_build: {
commands: ["n 16"],
},
},
}),
rolePolicy: [
new iam.PolicyStatement({
actions: ["<...>:<...>"],
resources: ["<...>"],
}),
],
},
}
);
What did you expect to happen?
Pipeline result:
Time taken 30s blahblah :D
What actually happened?
Failed to load notices from cache: Error: ENOENT: no such file or directory, open '/root/.cdk/cache/notices.json'
Error on request: Error: read ETIMEDOUT
Notices refreshed
Error on request: Error: read ETIMEDOUT
Failed to get tree.json file: Error: cdk.out/tree.json: ENOTDIR: not a directory, open 'cdk.out/tree.json'
CDK CLI Version
2.13.0
Framework Version
No response
Node.js Version
17
OS
MacOs
Language
Typescript
Language Version
TS 4
Other information
No response
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 13
- Comments: 16 (2 by maintainers)
Commits related to this issue
- chore(cli): improve error message when tree.json not found (#19887) Related to https://github.com/aws/aws-cdk/issues/19234. This improves the log wording so it's more clear this is not a "hard stop" ... — committed to aws/aws-cdk by Chriscbr 5 years ago
- chore(cli): improve error message when tree.json not found (#19887) Related to https://github.com/aws/aws-cdk/issues/19234. This improves the log wording so it's more clear this is not a "hard stop" ... — committed to StevePotter/aws-cdk by Chriscbr 5 years ago
It turns out
Failed to store notices in the cache: Error: ENOENT: no such file or directory, open '/root/.cdk/cache/notices.json'was a red herring. If anyone else is having this issue, the real problem is…This was happening because I didn’t have
"@aws-cdk/core:newStyleStackSynthesis": true,incdk.json. When I changed that, the error went away and self update succeeded.More about this issue:
https://github.com/aws/aws-cdk/issues/9606#issuecomment-672390345
Also running into this issue. Has anyone made it work with a monorepo?
Hi. I would like to share how I resolved the problem similar to this.
I had a similar issue like this but in my case, it failed at “UpdatePipeline” stage. This was my error log.
I re-ran the CDK workshop (https://cdkworkshop.com/) from the start to end. I compared my old CDK code with the new CDK code and found out there were quite much of difference. I carefully merged the new code to my old code base and it worked like a charm. 😎
For your information, this is my code change.
I am not completely sure which of this code change did the trick but my hunch tells me maybe it’s related with changing from
ShellSteptoCodeBuildStep.I hope it helps.
Hi there - I’ve also noticed this error on some CodeBuild jobs, but I believe this error message “Failed to get tree.json file” is actually just intended to be an debug message as part of the CDK notices mechanism. When it gets printed, we actually catch the error so that it does not cause the CDK command to fail. This is based on what I found from digging into our source code here: https://github.com/aws/aws-cdk/blob/697fdbe71642c93492c38e834e654ed736a9edb4/packages/aws-cdk/lib/notices.ts#L322-L329
I think it’s possible that in these scenarios, the cause of build failures may be something different in the build logs. Here’s an example from our build, showing that the actual error is located nearby:
I’m not totally sure why this is printed red in codebuild when other “debug” lines aren’t printed red, but I’ve submitted a PR that should try and improve the wording (#19887).
cc @otaviomacedo
@gbvanrenswoude Thanks for sharing. Then it must have been some other problem. Since the CDK workshop is an open source, let me share the typescript + CodePipeline working code (cdk-workshop-v2.16.0.tar.gz) based on the latest CDK (v2.16.0). I checked it with my AWS account and CodePipeline deployed fine.
But, as a side note, I would like to a comment that since CDK is so rapidly upgrading, it is forcing the production & previously-stable users to upgrade to the latest CDK. I mean there shouldn’t be deployment problem if the user didn’t touch anything except their code.