Skip to content

Commit

Permalink
fix(lambda-nodejs): incorrect SDK v2 warning generated
Browse files Browse the repository at this point in the history
  • Loading branch information
plumdog committed Sep 5, 2023
1 parent d69c51a commit 9eea420
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class Bundling implements cdk.BundlingOptions {
// their environment.
if (isV2Runtime && externals.some((pkgName) => pkgName.startsWith('@aws-sdk/'))) {
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.');
} else if (externals.includes('aws-sdk')) {
} else if (!isV2Runtime && externals.includes('aws-sdk')) {
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.');
}

Expand Down
36 changes: 36 additions & 0 deletions packages/aws-cdk-lib/aws-lambda-nodejs/test/bundling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,24 @@ test('bundling with <= Node16 warns when sdk v3 is external', () => {
);
});

test('bundling with <= Node16 does not warn with default externalModules', () => {
const myStack = new Stack(app, 'MyTestStack2');
Bundling.bundle(myStack, {
entry,
projectRoot,
depsLockFilePath,
runtime: Runtime.NODEJS_16_X,
architecture: Architecture.X86_64,
});

Annotations.fromStack(myStack).hasNoWarning('*',
'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]',
);
Annotations.fromStack(myStack).hasNoWarning('*',
'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]',
);
});

test('bundling with >= Node18 warns when sdk v3 is external', () => {
Bundling.bundle(stack, {
entry,
Expand All @@ -897,6 +915,24 @@ test('bundling with >= Node18 warns when sdk v3 is external', () => {
);
});

test('bundling with >= Node18 does not warn with default externalModules', () => {
const myStack = new Stack(app, 'MyTestStack3');
Bundling.bundle(myStack, {
entry,
projectRoot,
depsLockFilePath,
runtime: Runtime.NODEJS_18_X,
architecture: Architecture.X86_64,
});

Annotations.fromStack(myStack).hasNoWarning('*',
'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]',
);
Annotations.fromStack(myStack).hasNoWarning('*',
'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]',
);
});

test('bundling with NODEJS_LATEST warns when any dependencies are external', () => {
Bundling.bundle(stack, {
entry,
Expand Down

0 comments on commit 9eea420

Please sign in to comment.