aws_lambda_nodejs: @smithy/service-error-classification Missing in Lambda 22_X Environment #33099
Labels
@aws-cdk/aws-lambda-nodejs
bug
This issue is a bug.
effort/medium
Medium work item – several days of effort
p3
Describe the bug
When using the
aws-xray-sdk-core
package (possibly others as well) in a Lambda with the NodejsFunction using the now default@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages
flag set totrue
it will fail to execute as the@smithy/service-error-classification
will not be bundled and seems absent from the default packages installed in the runtime.Regression Issue
Last Known Working CDK Version
The version before #31639 was merged and
"@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages": true
was not the default.Expected Behavior
The bundled JS should work on the NodeJS 22 runtime.
Possible solutions:
--external
options for the constructs bundling capabilities so the missing packages will get bundled instead of the complete exclusion of@smithy/
ataws-cdk/packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts
Line 137 in ecbe1bf
@smithy/*
libraries like@smithy/service-error-classification
(and possibly others) to the lambda environments bundled packages.Current Behavior
All
@smithy/*
packages are externalized by esbuild even though some might not be present in the lambda environment.Reproduction Steps
"@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages": true
in thecdk.json
Stack:
handler.ts
This will result in the following asset bundle for the lambda code:
And when executed will result in:
Possible Solution
As a workaround you can add the module problematic smithy modules to the
nodeModules
option of theNodejsFunction
bundling options to ship them in thenode_modules
folder.Additional Information/Context
No response
CDK CLI Version
2.176.0
Framework Version
No response
Node.js Version
22_X
OS
macOS 15.2
Language
TypeScript
Language Version
No response
Other information
See https://dev.classmethod.jp/articles/fix-cdk-nodejs-functions-bundle-error/ for more analysis
The text was updated successfully, but these errors were encountered: