Skip to content
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

fix(lambda-nodejs): support bundling aws-sdk as part of the bundled code asset #29207

Merged
merged 5 commits into from
Mar 5, 2024

Conversation

jonife
Copy link
Contributor

@jonife jonife commented Feb 21, 2024

Issue # (if applicable)

#25492.

Closes #.
#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


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@jonife jonife changed the title support bundling aws-sdk as part of the bundled code asset fix: support bundling aws-sdk as part of the bundled code asset Feb 21, 2024
@github-actions github-actions bot added the p2 label Feb 21, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team February 21, 2024 23:36
@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Feb 21, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation aws-cdk-automation dismissed their stale review February 22, 2024 21:49

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Feb 22, 2024
@garysassano
Copy link

I like the proposal, but I think calling the option bundleAwsSDK instead of useAwsSDK would make it clearer. The name useAwsSDK as a true/false value doesn't clearly convey whether you want to use the Lambda Provided SDK or supply your own.

@@ -263,7 +265,7 @@ export class Bundling implements cdk.BundlingOptions {

// Create dummy package.json, copy lock file if any and then install
depsCommand = chain([
isPnpm ? osCommand.write(pathJoin(options.outputDir, 'pnpm-workspace.yaml'), ''): '', // Ensure node_modules directory is installed locally by creating local 'pnpm-workspace.yaml' file
isPnpm ? osCommand.write(pathJoin(options.outputDir, 'pnpm-workspace.yaml'), '') : '', // Ensure node_modules directory is installed locally by creating local 'pnpm-workspace.yaml' file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] : Is the space intentional? It is there at couple of places in this file.

Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as the other PR on the title, changes look good. But we should add the new property to README

@paulhcsun paulhcsun changed the title fix: support bundling aws-sdk as part of the bundled code asset fix(lambda-node): support bundling aws-sdk as part of the bundled code asset Feb 29, 2024
@paulhcsun paulhcsun changed the title fix(lambda-node): support bundling aws-sdk as part of the bundled code asset fix(lambda-nodejs): support bundling aws-sdk as part of the bundled code asset Feb 29, 2024
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: f87034e
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for contributing!

Copy link
Contributor

mergify bot commented Mar 5, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 2378635 into aws:main Mar 5, 2024
10 checks passed
@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Mar 5, 2024
@gshpychka
Copy link
Contributor

@jonife Wouldn't this be a breaking change for those who included the AWS SDK by setting externalModules to an empty array?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants