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

fix(lambda-nodejs): incorrect SDK v2 warning generated #27014

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Appears that the warnings don't get cleared from the shared stack after each run. This could invalidate some of the other tests in this file, but I decided to just fix it for my new tests, which fail without it.

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
Loading