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): do not add unused environment variable by default for sdk v3 lambda runtimes #30117

Merged
merged 10 commits into from
May 20, 2024

Conversation

scanlonp
Copy link
Contributor

@scanlonp scanlonp commented May 8, 2024

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

@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p1 labels May 8, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team May 8, 2024 23:31
@scanlonp scanlonp changed the title chore(lambda-nodejs): do not add unused environment variable by default in js sdk v3 lambda runtimes chore(lambda-nodejs): do not add unused environment variable by default for sdk v3 lambda runtimes May 8, 2024
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label May 8, 2024
when working with the AWS SDK for JavaScript. Set the `awsSdkConnectionReuse` prop to `false` to disable it.
when working with the AWS SDK v2 for JavaScript. Set the `awsSdkConnectionReuse` prop to `false` to disable it.

The AWS SDK v3 for JavaScript does not include the environment variable set by `awsSdkConnectionReuse`. See [this guide](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/node-reusing-connections.html) for information about reusing connections. Therefore, for runtimes >= Node 18, which include SDK v3, the prop defaults to `false`, and must be explicitly set to `true` in order for the environment variable to be set.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would setting it to true do anything in sdk v3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, the property does not exist. I believe it has no effect whatsoever.

@@ -43,15 +43,19 @@ export interface NodejsFunctionProps extends lambda.FunctionOptions {
readonly runtime?: lambda.Runtime;

/**
* The `AWS_NODEJS_CONNECTION_REUSE_ENABLED` environment variable does not exist in the AWS SDK for JavaScript v3.
*
* This prop will be deprecated when the Lambda Node16 runtime is deprecated on June 12, 2024.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also add a @see and the link to where this deadline is mentioned

Comment on lines +130 to +131
Annotations.of(scope).addWarningV2('aws-cdk-lib/aws-lambda-nodejs:unusedSdkEvironmentVariable', 'The AWS_NODEJS_CONNECTION_REUSE_ENABLED environment variable does not exist in SDK v3. You have explicitly set `awsSdkConnectionReuse`; please make sure this is intentional.');
this.addEnvironment('AWS_NODEJS_CONNECTION_REUSE_ENABLED', '1', { removeInEdge: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this env variable do anything in sdk v3? Is this for backward compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left this so users can set it if need be (they can also configure their environment variables directly). I figured some users may define >= Node 18 runtimes, but bundle the sdk v2 into their v2 handlers, and this would be for ease of use / backwards compatibility.

@scanlonp
Copy link
Contributor Author

@Mergifyio update

Copy link
Contributor

mergify bot commented May 14, 2024

update

✅ Branch has been successfully updated

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label May 16, 2024
@scanlonp
Copy link
Contributor Author

@Mergifyio update

Copy link
Contributor

mergify bot commented May 20, 2024

update

❌ Mergify doesn't have permission to update

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/github-merit-badger.yml without workflows permission

Copy link
Contributor

@colifran colifran left a comment

Choose a reason for hiding this comment

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

Nice job!

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

Copy link
Contributor

mergify bot commented May 20, 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 cf3599b into aws:main May 20, 2024
14 checks passed
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*
@aws-cdk-automation
Copy link
Collaborator

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/medium Medium work item – several days of effort p1 pr/needs-maintainer-review This PR needs a review from a Core Team Member
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
4 participants