Skip to content

Commit 856b303

Browse files
authored
fix(lambda-nodejs): incorrect SDK v2 warning generated (#27014)
Fixes to remove an incorrectly generated warning when using Node JS runtime <= 16 with `NodejsFunction` Closes #26966 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent d69c51a commit 856b303

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class Bundling implements cdk.BundlingOptions {
137137
// their environment.
138138
if (isV2Runtime && externals.some((pkgName) => pkgName.startsWith('@aws-sdk/'))) {
139139
cdk.Annotations.of(scope).addWarningV2('@aws-cdk/aws-lambda-nodejs:sdkV3NotInRuntime', 'If you are relying on AWS SDK v3 to be present in the Lambda environment already, please explicitly configure a NodeJS runtime of Node 18 or higher.');
140-
} else if (externals.includes('aws-sdk')) {
140+
} else if (!isV2Runtime && externals.includes('aws-sdk')) {
141141
cdk.Annotations.of(scope).addWarningV2('@aws-cdk/aws-lambda-nodejs:sdkV2NotInRuntime', 'If you are relying on AWS SDK v2 to be present in the Lambda environment already, please explicitly configure a NodeJS runtime of Node 16 or lower.');
142142
}
143143

packages/aws-cdk-lib/aws-lambda-nodejs/test/bundling.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,24 @@ test('bundling with <= Node16 warns when sdk v3 is external', () => {
882882
);
883883
});
884884

885+
test('bundling with <= Node16 does not warn with default externalModules', () => {
886+
const myStack = new Stack(app, 'MyTestStack2');
887+
Bundling.bundle(myStack, {
888+
entry,
889+
projectRoot,
890+
depsLockFilePath,
891+
runtime: Runtime.NODEJS_16_X,
892+
architecture: Architecture.X86_64,
893+
});
894+
895+
Annotations.fromStack(myStack).hasNoWarning('*',
896+
'If you are relying on AWS SDK v3 to be present in the Lambda environment already, please explicitly configure a NodeJS runtime of Node 18 or higher. [ack: @aws-cdk/aws-lambda-nodejs:sdkV3NotInRuntime]',
897+
);
898+
Annotations.fromStack(myStack).hasNoWarning('*',
899+
'If you are relying on AWS SDK v2 to be present in the Lambda environment already, please explicitly configure a NodeJS runtime of Node 16 or lower. [ack: @aws-cdk/aws-lambda-nodejs:sdkV2NotInRuntime]',
900+
);
901+
});
902+
885903
test('bundling with >= Node18 warns when sdk v3 is external', () => {
886904
Bundling.bundle(stack, {
887905
entry,
@@ -897,6 +915,24 @@ test('bundling with >= Node18 warns when sdk v3 is external', () => {
897915
);
898916
});
899917

918+
test('bundling with >= Node18 does not warn with default externalModules', () => {
919+
const myStack = new Stack(app, 'MyTestStack3');
920+
Bundling.bundle(myStack, {
921+
entry,
922+
projectRoot,
923+
depsLockFilePath,
924+
runtime: Runtime.NODEJS_18_X,
925+
architecture: Architecture.X86_64,
926+
});
927+
928+
Annotations.fromStack(myStack).hasNoWarning('*',
929+
'If you are relying on AWS SDK v3 to be present in the Lambda environment already, please explicitly configure a NodeJS runtime of Node 18 or higher. [ack: @aws-cdk/aws-lambda-nodejs:sdkV3NotInRuntime]',
930+
);
931+
Annotations.fromStack(myStack).hasNoWarning('*',
932+
'If you are relying on AWS SDK v2 to be present in the Lambda environment already, please explicitly configure a NodeJS runtime of Node 16 or lower. [ack: @aws-cdk/aws-lambda-nodejs:sdkV2NotInRuntime]',
933+
);
934+
});
935+
900936
test('bundling with NODEJS_LATEST warns when any dependencies are external', () => {
901937
Bundling.bundle(stack, {
902938
entry,

0 commit comments

Comments
 (0)