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

chore(lambda-nodejs): stop bundling lambda provided sdk by default #25717

Closed

Conversation

fynnfluegge
Copy link
Contributor

@fynnfluegge fynnfluegge commented May 24, 2023

This PR disables bundling of Lambda provided SDK by default which leads to lower cold starts since aws-sdk is removed from asset bundle as extensively explained and benchmarked in the related issue.

Breaking change. An opt im property is added to bundle the aws-sdk as it has been the default before.

Closes #25492.


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

@gitpod-io
Copy link

gitpod-io bot commented May 24, 2023

@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK labels May 24, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team May 24, 2023 13:21
@fynnfluegge fynnfluegge marked this pull request as ready for review May 24, 2023 21:25
@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 May 24, 2023
@corymhall corymhall self-assigned this May 30, 2023
Copy link
Contributor

@corymhall corymhall left a comment

Choose a reason for hiding this comment

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

@fynnfluegge thanks for the PR! In general I like this change, I think we should be bundling everything by default. I'm worried about making this change the default without a feature flag though.

I tested the existing integration tests and the aws-sdk v2 test timed out until I increased the memorySize of the function. This is just one breaking point, but it makes me think that there could be more that we are not thinking of.

  1. Lets put this behind a feature flag so that we don't change the behavior for existing users
  2. Is there a minimum required memory setting for aws-sdk?

packages/aws-cdk-lib/aws-lambda-nodejs/lib/types.ts Outdated Show resolved Hide resolved
@corymhall corymhall removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 1, 2023
Copy link
Contributor

@corymhall corymhall left a comment

Choose a reason for hiding this comment

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

@fynnfluegge thanks for the PR! In general I like this change, I think we should be bundling everything by default. I'm worried about making this change the default without a feature flag though.

I tested the existing integration tests and the aws-sdk v2 test timed out until I increased the memorySize of the function. This is just one breaking point, but it makes me think that there could be more that we are not thinking of.

  1. Lets put this behind a feature flag so that we don't change the behavior for existing users
  2. Is there a minimum required memory setting for aws-sdk?

@@ -37,6 +37,9 @@ class SdkV3TestStack extends Stack {
this.lambdaFunction = new lambda.NodejsFunction(this, 'external-sdk-v3', {
entry: path.join(__dirname, 'integ-handlers/dependencies-sdk-v3.ts'),
runtime: Runtime.NODEJS_18_X,
bundling: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove this so that the integ test will test the new behavior?

Can you also add diffAssets: true to the IntegTest

Copy link
Contributor Author

@fynnfluegge fynnfluegge Jun 5, 2023

Choose a reason for hiding this comment

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

Sure, modified it to test both behaviours ✅
However, the test that uses the default bundled aws-sdk doesn't pass since it cannot resolve the import?

Screenshot 2023-06-05 at 10 51 39

Usually it should be bundled as default, any idea how to test this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it may be because there is no lock file. I would try adding a new sub folder for this handler with a minimal package.json and package-lock.json.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's exactly what I did 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I think for this test we have to have the bundling actually perform an npm install.

    this.lambdaFunction = new lambda.NodejsFunction(this, 'external-sdk-v3', {
      entry: path.join(__dirname, 'integ-handlers/v3/dependencies-sdk-v3.ts'),
      runtime: Runtime.NODEJS_18_X,
      depsLockFilePath: path.join(__dirname, 'integ-handlers/v3/package-lock.json'),
      bundling: {
        bundleLambdaProvidedAwsSdk: true,
        commandHooks: {
          beforeInstall() {
            return [];
          },
          afterBundling() {
            return [];
          },
          beforeBundling(inputDir, _outputDir) {
            return [`cd ${inputDir}`, 'npm install --ci'];
          },
        },
      },
    });

Copy link
Contributor Author

@fynnfluegge fynnfluegge Jun 9, 2023

Choose a reason for hiding this comment

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

Okay that seems to work ✅
So I want to create the new snapshots now but that leads me into a rabbit hole 😄
When running yarn integ --update-on-failed aws-lambda-nodejs/test/integ.dependencies.js it says for the test with the bundled sdk:
Screenshot 2023-06-09 at 16 14 51

It is the Response object is too long error which relates to several issues i.e. #2825. Any idea how to do a workaround for this?

@mergify mergify bot dismissed corymhall’s stale review June 4, 2023 09:45

Pull request has been modified.

@fynnfluegge
Copy link
Contributor Author

@fynnfluegge thanks for the PR! In general I like this change, I think we should be bundling everything by default. I'm worried about making this change the default without a feature flag though.

I tested the existing integration tests and the aws-sdk v2 test timed out until I increased the memorySize of the function. This is just one breaking point, but it makes me think that there could be more that we are not thinking of.

  1. Lets put this behind a feature flag so that we don't change the behavior for existing users
  2. Is there a minimum required memory setting for aws-sdk?

Hey @corymhall thanks for reviewing!

  1. Feature flag sounds reasonable, will put the changes behind it ✅
  2. Not sure 🤔 Will take a look at this

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 21070da
  • Result: FAILED
  • Build Logs (available for 30 days)

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

@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@aws-cdk-automation
Copy link
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@aws-cdk-automation aws-cdk-automation added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label Jul 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_lambda_nodejs: Using Lambda Provided SDK by default in NodejsFunction leads to higher cold starts
3 participants