Skip to content

Commit

Permalink
fix(lambda-nodejs): support bundling aws-sdk as part of the bundled c…
Browse files Browse the repository at this point in the history
…ode asset (#29207)

### Issue # (if applicable)
#25492.

Closes #<issue number here>.
#25492.

### Reason for this change
The BundlingOptions in NodejsFunction construct removes AWS SDK dependencies by default.

This uses Lambda Provided SDK in the resulting function. This has higher cold start than a bundled function with AWS SDK dependencies included.

This happens, because the Node.js runtime has to do module resolution and go through multiple files while reading dependency code in the bundled function which uses Lambda Provided SDK. When SDK in bundled with the function code, the cold starts are lower as the as Node.js runtime has to read single file without any module resolution.

Result from reproduction:

{
'NodejsFunction default (uses Lambda Provided SDK)': 1227.1435,
'NodejsFunction custom (uses Customer Deployed SDK)': 929.441
}

related to this issue: #25492



### Description of changes
While maintaining backward compatibility, an new option `useAwsSDK` was introduced to include the sdk in the code asset


yes kindly refer to the above

### Description of how you validated changes
Added both unit and integration test 


yes 

```
Running integration tests for failed tests...

Running in parallel across regions: us-east-1, us-east-2, us-west-2
Running test /Users/jonife/Documents/dev/lambda-tooling/cdk/aws-cdk/packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.dependencies.js in us-east-1
  SUCCESS    aws-lambda-nodejs/test/integ.dependencies-LambdaDependencies/DefaultTest 329.553s
       AssertionResultsLambdaInvoke5050b1f640cc49956b59f2a71febe95c - success
      AssertionResultsLambdaInvokee35a5227846e334cb95a90bacfbfb877 - success
      AssertionResultsLambdaInvoke7d0602e4b9f40ae057f935d874b5f971 - success

Test Results: 

Tests:    1 passed, 1 total
✨  Done in 337.42s.
```

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jonife authored Mar 5, 2024
1 parent 82690f7 commit 2378635
Show file tree
Hide file tree
Showing 14 changed files with 71,071 additions and 15 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2378635

Please sign in to comment.