(aws-cdk-lib): cdk commands hang on Yarn install step when using Runtime.NODEJS_20_X
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 71
Description
### Describe the bug
I am trying to run `cdk` commands, such as `cdk diff` on a stack that contains `NodejsFunction`s with `runtime`s set to `Runtime.NODEJS_20_X`. However, the commands always hang when the build image, `public.ecr.aws/sam/build-nodejs20.x@sha256:f09695497aac919ac48544640265` tries to install `yarn`:
```
[+] Building 317.2s (4/13)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 37B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for public.ecr.aws/sam/build-nodejs20.x:latest 0.9s
=> CACHED [ 1/10] FROM public.ecr.aws/sam/build-nodejs20.x@sha256:f09695497aac919ac48544640265 0.0s
=> [ 2/10] RUN npm install --global yarn@1.22.5 316.1s
```
If `runtime` is set to `Runtime.NODEJS_18_X`, yarn is installed correctly.
Also if one just takes the Dockerfile from https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-lambda-nodejs/lib/Dockerfile and sets ARG IMAGE=IMAGE=public.ecr.aws/sam/build-nodejs20.x, the `yarn` install step completes successfully.
### Expected Behavior
Yarn is installed within seconds and the build continues.
### Current Behavior
`RUN npm install --global yarn@1.22.5` step continues indefinitely
### Reproduction Steps
Create a project that has a `NodeJSFunction` in it:
```
const customMessageHandler = new NodejsFunction(this, 'CognitoMessageHandler', {
memorySize: 128,
timeout: Duration.seconds(5),
runtime: Runtime.NODEJS_20_X,
handler: 'handler',
projectRoot: path.join(__dirname, '../../src/myproject'),
depsLockFilePath: path.join(__dirname, '../../src/myproject/yarn.lock'),
entry: path.join(__dirname, '../../src/myproject/src/index.ts'),
bundling: {
minify: true,
loader: {
'.html': 'text'
}
}
});
```
Run `cdk diff --profile myprofile`
### Possible Solution
_No response_
### Additional Information/Context
Might be related to https://github.com/aws/aws-sam-build-images/issues/116
### CDK CLI Version
2.118.0 (build a40f2ec)
### Framework Version
2.117.0
### Node.js Version
v20.10.0
### OS
macOS 13.1
### Language
TypeScript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Start with packages/aws-cdk-lib/aws-lambda-nodejs/lib/Dockerfile and compare the NODEJS_20_X image behavior with NODEJS_18_X. Reproduce with a NodejsFunction and `cdk diff`, focusing on the `npm install --global yarn@1.22.5` step; done means Yarn installs promptly and bundling continues. The linked aws-sam-build-images issue may provide relevant context.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, docker, node.js, typescript
- Domain
- build-system, cli, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100