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): set default value of awsSdkConnectionReuse to false (under feature flag) #29538

Closed
wants to merge 12 commits into from

Conversation

badmintoncryer
Copy link
Contributor

@badmintoncryer badmintoncryer commented Mar 19, 2024

Issue # (if applicable)

Closes #29497 .

Reason for this change

Reference to #29497

The AWS SDK for JavaScript v3 is included by default in AWS Lambda Node.js 18 and Node.js 20 runtimes.

NodejsFunction construct comes with an awsSdkConnectionReuse optional prop, which is set to true by default. This default automatically sets the AWS_NODEJS_CONNECTION_REUSE_ENABLED environment variable to 1 in the Lambda function's configuration.

However, it has been identified that the AWS_NODEJS_CONNECTION_REUSE_ENABLED environment variable aws/aws-sdk-js-v3#5883, rendering the variable obsolete for those utilizing the more recent Lambda runtimes. This situation not only leads to unnecessary configuration, but it also has a performance impact. The inclusion of this redundant environment variable is associated with a 20ms increase in cold start times, highlighting an opportunity for performance improvement by removing this default setting for those who do not require it.

Description of changes

Change default value of awsSdkConnectionReuse from true to false

Description of how you validated changes

I have added both unit and integ tests.

Checklist


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

@github-actions github-actions bot added the star-contributor [Pilot] contributed between 25-49 PRs to the CDK label Mar 19, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team March 19, 2024 11:43
@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p1 labels Mar 19, 2024
@badmintoncryer badmintoncryer marked this pull request as ready for review March 21, 2024 13:35
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Mar 21, 2024
@shikha372 shikha372 self-assigned this Mar 21, 2024
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@TheRealAmazonKendra
Copy link
Contributor

TheRealAmazonKendra commented Mar 27, 2024

We will actually be removing v2 altogether in the next few weeks or so. Given that, I don't think we should add an additional feature flag or update the default here.

ETA: sdk v2, not cdk v2

@badmintoncryer
Copy link
Contributor Author

@TheRealAmazonKendra Does this mean that CDK v3 will be launched in a few weeks?!

@TheRealAmazonKendra
Copy link
Contributor

@TheRealAmazonKendra Does this mean that CDK v3 will be launched in a few weeks?!

Sdk v3, not cdk. I should have specified more clearly.

@badmintoncryer
Copy link
Contributor Author

@TheRealAmazonKendra I see. I'm sorry for the misunderstanding.

I think the current default values are for SDK v2, and this PR will optimize the default settings for SDK v3.
If SDK v2 becomes obsolete, I believe it would be even more appropriate to apply this PR. What do you think?

@shikha372
Copy link
Contributor

Hi @badmintoncryer ,
To confirm the expected behaviour when we move to SDK v3, if its expected to be set to false by default, we wouldn't need this feature flag in which case might need to remove this code altogether ?

@badmintoncryer
Copy link
Contributor Author

Hi @shikha372.
SDK V3 does not utilize AWS_NODEJS_CONNECTION_REUSE_ENABLED option but AWS CDK generates this environment value by default. Original issue says that this redundant environment value affects to lambda's latency.

Therefore, I think it is necessary to update the default value of awsSdkConnectionReuse option in
NodejsFunctionProps.
If it's okay to just make a modification to change the default value of awsSdkConnectionReuse, I believe the feature flag is not necessary. However, I think that would be a breaking change, which is why I've implemented it using a feature flag.

I might be misunderstanding various things. Please don't hesitate to point out any issues.

@TheRealAmazonKendra
Copy link
Contributor

When we move from sdk v2 to v3, we'll probably just deprecate this field as it will no longer have any relevance to this construct.

I'm not precisely sure of what the path forward on this construct library as a whole will be but, in contrast to our normal practice of not pushing breaking changes or forcing upgrades, we will have to. Anyone still on sdkv2 will also still be on the node16 Lambda runtime (this is the most recent it supports).

On July 15th, no new Lambda functions will be able to be created with this runtime and then on August 15th, all updates to existing Lambda functions will be blocked. See: https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html

Since the consequences of still being on that runtime are pretty major, this might be a case where we do use a breaking change and force an update.

THAT BEING SAID, we haven't settled on an exact plan here so don't take this as the absolute path forward. Just my thoughts as we begin to plan this upgrade.

@badmintoncryer
Copy link
Contributor Author

@TheRealAmazonKendra
Thank you for your detailed response; I now have a clear understanding of the situation.

For now, I'll leave this PR as it is. I would appreciate it if you could reply here once a decision has been made.
Of course, I am also prepared to update the PR to a breaking change without the use of feature flags if that becomes necessary. Please just let me know.

mergify bot pushed a commit that referenced this pull request May 20, 2024
…lt for sdk v3 lambda runtimes (#30117)

Closes #29497
Related to #29538

### Reason for this change

The `AWS_NODEJS_CONNECTION_REUSE_ENABLED` does not exist in SDK v3. Including it in the environment can add to cold start times.

### Description of changes

For Lambda runtimes >= Node 18, do not set the variable by default. If set explicitly, give the user a warning.

We can plan to simplify this logic & deprecate the property after we deprecate Node 16 and remove it as the default runtime for this construct.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@scanlonp
Copy link
Contributor

Hey @badmintoncryer, wanted to give you an update on the path we took with this.

Along the lines of what Kendra was saying, we want to keep some of the decisions that straddle the breaking change line to be made by the team itself. In that vein, I made this change in #30117 in a similar manner without the feature flag at all. There is also the possibility that when we deprecate the Node 16 runtime, we will deprecate the prop altogether.

I think we will want to take that approach for most of the Node 16 / SDK v2 upgrades. I don't want you to feel like we took this PR from you, and I certainly consulted it when making mine, but we wanted to have full control on this type of change.

Again, greatly appreciate you taking the time to submit this PR.

@scanlonp scanlonp closed this May 20, 2024
mazyu36 pushed a commit to mazyu36/aws-cdk that referenced this pull request May 22, 2024
…lt for sdk v3 lambda runtimes (aws#30117)

Closes aws#29497
Related to aws#29538

### Reason for this change

The `AWS_NODEJS_CONNECTION_REUSE_ENABLED` does not exist in SDK v3. Including it in the environment can add to cold start times.

### Description of changes

For Lambda runtimes >= Node 18, do not set the variable by default. If set explicitly, give the user a warning.

We can plan to simplify this logic & deprecate the property after we deprecate Node 16 and remove it as the default runtime for this construct.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
atanaspam pushed a commit to atanaspam/aws-cdk that referenced this pull request Jun 3, 2024
…lt for sdk v3 lambda runtimes (aws#30117)

Closes aws#29497
Related to aws#29538

### Reason for this change

The `AWS_NODEJS_CONNECTION_REUSE_ENABLED` does not exist in SDK v3. Including it in the environment can add to cold start times.

### Description of changes

For Lambda runtimes >= Node 18, do not set the variable by default. If set explicitly, give the user a warning.

We can plan to simplify this logic & deprecate the property after we deprecate Node 16 and remove it as the default runtime for this construct.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/medium Medium work item – several days of effort p1 pr/needs-maintainer-review This PR needs a review from a Core Team Member star-contributor [Pilot] contributed between 25-49 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_lambda_nodejs: Unexisting AWS_NODEJS_CONNECTION_REUSE_ENABLED env variable set to 1 as default
5 participants