-
Notifications
You must be signed in to change notification settings - Fork 634
Description
Checkboxes for prior research
- I've gone through Developer Guide and API reference
- I've checked AWS Forums and StackOverflow.
- I've searched for previous similar issues and didn't find any solution.
Describe the bug
I noticed that our lambda bundle contains pretty much all S3 and DynamoDB commands, even though I recently refactored to use the smaller, non-aggregated clients instead.
Regression Issue
- Select this option if this issue appears to be a regression.
SDK version number
@aws-sdk/client-s3 3.749.0, @aws-sdk/client-dynamodb 3.749.0
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v22.2.0
Reproduction Steps
Our setup: esbuild, using the following config:
{
bundle: true,
treeShaking: true,
minify: true,
sourcemap: true,
legalComments: "none",
platform: "node",
target: "es2020",
mainFields: ['module', 'main'],
conditions: [
'wintercg',
'import',
'module',
'node',
],
define: {
'process.env.NODE_ENV': '"production"',
},
loader: {
".node": "file",
},
alias: {
'lodash': 'lodash-es',
},
}
Observed Behavior
From what I can tell, the tree shaking stops working because the "S3.js" and "DynamoDB.js" files include a list of all commands to support on the clients. Even though we're not importing those files/clients (and use the raw S3Client
and DynamoDBClient
instead), the file likely still gets evaluated:
createAggregatedClient(commands, DynamoDB); |
aws-sdk-js-v3/clients/client-s3/src/S3.ts
Line 2096 in 5f1be93
createAggregatedClient(commands, S3); |
There already has been an issue up on StackOverflow about this:
https://stackoverflow.com/q/79169593/1397894
Here is an analysis by esbuild:
Imported file src/services/dynamoDbClient.ts contains:
import "@aws-sdk/client-dynamodb";
Imported file ../../node_modules/.pnpm/@[email protected]/node_modules/@aws-sdk/client-dynamodb/dist-es/index.js contains:
import "./commands";
Imported file ../../node_modules/.pnpm/@[email protected]/node_modules/@aws-sdk/client-dynamodb/dist-es/commands/index.js contains:
import "./DescribeKinesisStreamingDestinationCommand";
So imported file ../../node_modules/.pnpm/@[email protected]/node_modules/@aws-sdk/client-dynamodb/dist-es/commands/DescribeKinesisStreamingDestinationCommand.js is included in the bundle.
Expected Behavior
Only the commands used should be included in the bundle.
Possible Solution
When importing the S3 client directly, via using the path directly, the issue goes away. However, this is impractical for the DynamoDB client, as we'd need to do the same for every command import that we use.
Additional Information/Context
This issue is based on taking the recommendations mentioned in #3542 already into account.