-
Notifications
You must be signed in to change notification settings - Fork 4k
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
NodejsFunction: bundler fails with unclear error message when using node 12 runtime #25710
Comments
The node 12 runtime option is marked as deprecated in CDK, but it's still a valid configuration for functions that were created on node 12, so we can't just throw an error if someone uses node 12. I'm not sure how we can throw a clear warning message in this exact case of container failure either, that could be pretty tricky. Thanks for letting us know this could be clearer |
@peterwoodworth Yeah, that's fair enough; though I guess in this case, when CDK chooses to use the container to build the function, it's failing outright.. so perhaps that is an error in the container maybe then? I'm not really sure of the internals of it all, but the fact that a Node I'm not sure if that bug is in the build container itself, or in something that CDK is passing to that container. If the former, it seems like a bug to be raised upstream with the build container repo. If it's something that CDK is passing to the build container, then either it should be fixed up so it doesn't cause the error (probably the ideal case, since you say Node
@peterwoodworth Mm, fair enough. Not too sure of the specifics on that side of things, so can't provide any further guidance. |
The following docs/references seem relevant here:
|
Looking deeper at this we can see that the aws-cdk/packages/aws-cdk-lib/aws-lambda-nodejs/lib/Dockerfile Lines 15 to 18 in 2dc6fba
This is then passed in from aws-cdk/packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts Lines 133 to 144 in 2dc6fba
While that part isn't being used to switch based on the Just above it, we can see that the Based on these 2 patterns, we could easily derive a 'use the correct/supported pnpm version for the runtime' pattern. It could look something like this: const runtime = props.runtime ?? Runtime.NODEJS_14_X
const pnpmVersion = ((runtime) => {
switch (runtime) {
case Runtime.NODEJS_4_3:
return '^1.27.0-1'
case Runtime.NODEJS_6_10:
return '^2.24.0-0'
case Runtime.NODEJS_8_10:
return '^3.8.1'
case Runtime.NODEJS_10_X:
return '^5.18.10'
case Runtime.NODEJS_12_X:
return '^6.35.1'
case Runtime.NODEJS_14_X:
return '^7.32.5'
default:
return '^8.5.1'
}
})(runtime) Then in the // Docker bundling
const shouldBuildImage = props.forceDockerBundling || !Bundling.esbuildInstallation;
this.image = shouldBuildImage ? props.dockerImage ?? cdk.DockerImage.fromBuild(path.join(__dirname, '../lib'),
{
buildArgs: {
...props.buildArgs ?? {},
// If runtime isn't passed use regional default, lowest common denominator is node14
- IMAGE: (props.runtime ?? Runtime.NODEJS_14_X).bundlingImage.image,
+ IMAGE: runtime.bundlingImage.image,
ESBUILD_VERSION: props.esbuildVersion ?? ESBUILD_MAJOR_VERSION,
+ PNPM_VERSION: pnpmVersion
},
platform: props.architecture.dockerPlatform,
})
: cdk.DockerImage.fromRegistry('dummy'); // Do not build if we don't need to Then finally, in the # Install pnpm
- RUN npm install --global pnpm@7.30.5
+ ARG PNPM_VERSION=0
+ RUN npm install --global pnpm@$PNPM_VERSION We can see the changelog's for various versions dropping pnpm support here:
And we can get the latest version of each major release here: As new major versions are released the Details on using the
Though if you want to pin to the exact latest versions at time of writing, just strip the leading |
I've submitted a PR with the above proposed solution here: |
Describe the bug
I'm in the process of upgrading from an old version of CDK
1.x
, to the latest CDK2.x
(2.80.0
).I had some old
NodejsFunction
code that was usingruntime: Runtime.NODEJS_12_X
Old code that caused error:
Expected Behavior
The framework would give me a more meaningful error message telling me what/where the issue was.
Current Behavior
Reproduction Steps
See above
Possible Solution
Throw a more useful error/warning at the CDK framework level that describes the issue, rather than it being surfaced through arbitrary warnings within a related docker build container.
Workaround
Manually figure out that the error relates to using
runtime: Runtime.NODEJS_12_X
, find it in your code, and update it to something supported such asruntime: Runtime.NODEJS_14_X
Additional Information/Context
N/A
CDK CLI Version
2.80.0 (build bbdb16a)
Framework Version
2.80.0
Node.js Version
v16.15.1
OS
macOS Ventura 13.3.1
Language
Typescript
Language Version
No response
Other information
N/A
The text was updated successfully, but these errors were encountered: