aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.47k stars 3.83k forks source link

aws-lambda-nodejs: Add support for bundling aws-sdk #28311

Open spolaka opened 8 months ago

spolaka commented 8 months ago

Describe the feature

NodejsFunction ESBuild by default excludes the aws sdk from the bundle. Excluding the aws sdk by default reduces the package size, but we observed this is adding additional time to load the aws sdk modules at the function runtime.

Sample function that uses aws sdk to read a dynamoDB table during the init phases takes 800ms if the aws sdk is excluded in the bundle and around 400ms if the aws sdk is bundled in the package.

Rightnow, the only option to include aws sdk in the bundle is to use NODEJS_LATEST as the runtome. I would like to request a feature to support an option to include aws sdk with any specific node runtime.

may be some option like

bundling:{
        includeAwsSdk: true, 
}

Use Case

This will reduce the time for the lambda run and thus improve latency and reduce the cost for the lambda function.

Proposed Solution

I would like to request a feature to support an option to include aws sdk with any specific node runtime.

may be some option like

bundling:{
        includeAwsSdk: true, 
}

Other Information

No response

Acknowledgements

CDK version used

2.96.0

Environment details (OS name and version, etc.)

macOS 13.6.2

samchungy commented 8 months ago

This is resolved simply by adding externalModules: [], to the bundling options

spolaka commented 8 months ago

This is resolved simply by adding externalModules: [], to the bundling options

Yes, I tried the following work arounds, but both has the limitations

  1. Use NODEJS_LATEST as runtime, disadvantage is we can not fully control the version of the Node runtime.
  2. Use externalModules: [], I can not use this when i have external modules that comes through lambda layers.

My proposal to have an attribute to control the inclusion of AWS SDK would not have disadvantages and can be used in all the scenarios.