-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
chore(lambda-nodejs): do not add unused environment variable by default for sdk v3 lambda runtimes #30117
Changes from 2 commits
e5695f5
af2be71
7c19a3d
a7bd120
9c192fe
510f49b
6a5865b
39cf5d6
fc40cc6
db24795
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,10 @@ import { Construct } from 'constructs'; | |
import { Bundling } from './bundling'; | ||
import { LockFile } from './package-manager'; | ||
import { BundlingOptions } from './types'; | ||
import { callsites, findUpMultiple } from './util'; | ||
import { callsites, findUpMultiple, isSdkV2Runtime } from './util'; | ||
import { Architecture } from '../../aws-lambda'; | ||
import * as lambda from '../../aws-lambda'; | ||
import { FeatureFlags } from '../../core'; | ||
import { Annotations, FeatureFlags } from '../../core'; | ||
import { LAMBDA_NODEJS_USE_LATEST_RUNTIME } from '../../cx-api'; | ||
|
||
/** | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
* | ||
* Info for Node 16 runtimes / SDK v2 users: | ||
* | ||
* Whether to automatically reuse TCP connections when working with the AWS | ||
* SDK for JavaScript. | ||
* SDK for JavaScript v2. | ||
* | ||
* This sets the `AWS_NODEJS_CONNECTION_REUSE_ENABLED` environment variable | ||
* to `1`. | ||
* | ||
* @see https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/node-reusing-connections.html | ||
* | ||
* @default true | ||
* @default - false (obsolete) for runtimes >= Node 18, true for runtimes <= Node 16. | ||
*/ | ||
readonly awsSdkConnectionReuse?: boolean; | ||
|
||
|
@@ -116,9 +120,16 @@ export class NodejsFunction extends lambda.Function { | |
handler: handler.indexOf('.') !== -1 ? `${handler}` : `index.${handler}`, | ||
}); | ||
|
||
// Enable connection reuse for aws-sdk | ||
if (props.awsSdkConnectionReuse ?? true) { | ||
this.addEnvironment('AWS_NODEJS_CONNECTION_REUSE_ENABLED', '1', { removeInEdge: true }); | ||
// Enable connection reuse for aws-sdk v2, do not set for sdk v3 | ||
if (isSdkV2Runtime(runtime)) { | ||
if (props.awsSdkConnectionReuse ?? true) { | ||
this.addEnvironment('AWS_NODEJS_CONNECTION_REUSE_ENABLED', '1', { removeInEdge: true }); | ||
} | ||
} else { | ||
if (props.awsSdkConnectionReuse) { | ||
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 }); | ||
Comment on lines
+133
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.