Skip to content

Commit 19ee46d

Browse files
authored
fix(lambda-nodejs): remove smithy models from bundling for AWS SDK v3 runtimes (under feature flag) (#31639)
### Issue # (if applicable) Closes #31610 ### Reason for this change for Node 18+ runtimes, since AWS Lambda includes AWS SDK v3 by default, and CDK excludes all the `@aws-sdk/*` packages because they’re expected to already be present. However, the CDK currently removes only the `@aws-sdk/*` packages when bundling for Node 18+ runtimes, but it does not remove the `@smithy/*` packages. This can cause a mismatch in versions between the `@smithy/*` packages and the AWS SDK packages that AWS Lambda provides. The mismatch can happen in the following scenarios. This is a pretty edge case but customers did encounter this issue. ``` /user-app/node_modules/ - /@smithy/* (v123) <-- this gets used because it wasn't deleted - /@aws-sdk/* (v123) <-- CDK removes `@aws-sdk/*` currently /lambda-hidden-folder/node_modules - /@smithy/* (v456) - /@aws-sdk/* (v456) <-- this gets used as fallback since the module is removed from node_modules by CDK ``` ### Description of changes Add a feature flag. When feature flag is set to true, we will also remove smithy models. ### Description of how you validated changes Added unit tests and integration tests. ### Checklist - [ ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent d0c99d8 commit 19ee46d

File tree

15 files changed

+852
-2
lines changed

15 files changed

+852
-2
lines changed

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.function-exclude-smithy-models.js.snapshot/NodeJsFunctionExcludeSmithyIntegDefaultTestDeployAssert8BE0D2D1.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.function-exclude-smithy-models.js.snapshot/NodeJsFunctionExcludeSmithyIntegDefaultTestDeployAssert8BE0D2D1.template.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.function-exclude-smithy-models.js.snapshot/asset.5f1efdee2910b237bc92c947c2621e653fadf9ce9ef02e797da9ec166a2d4270/index.js

+109
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.function-exclude-smithy-models.js.snapshot/cdk-integ-lambda-nodejs-18-exclude-smithy.assets.json

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"Resources": {
3+
"NodeJsFunctionServiceRole9AE046B6": {
4+
"Type": "AWS::IAM::Role",
5+
"Properties": {
6+
"AssumeRolePolicyDocument": {
7+
"Statement": [
8+
{
9+
"Action": "sts:AssumeRole",
10+
"Effect": "Allow",
11+
"Principal": {
12+
"Service": "lambda.amazonaws.com"
13+
}
14+
}
15+
],
16+
"Version": "2012-10-17"
17+
},
18+
"ManagedPolicyArns": [
19+
{
20+
"Fn::Join": [
21+
"",
22+
[
23+
"arn:",
24+
{
25+
"Ref": "AWS::Partition"
26+
},
27+
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
28+
]
29+
]
30+
}
31+
]
32+
}
33+
},
34+
"NodeJsFunction6DD2A8DD": {
35+
"Type": "AWS::Lambda::Function",
36+
"Properties": {
37+
"Code": {
38+
"S3Bucket": {
39+
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
40+
},
41+
"S3Key": "5f1efdee2910b237bc92c947c2621e653fadf9ce9ef02e797da9ec166a2d4270.zip"
42+
},
43+
"Handler": "index.handler",
44+
"Role": {
45+
"Fn::GetAtt": [
46+
"NodeJsFunctionServiceRole9AE046B6",
47+
"Arn"
48+
]
49+
},
50+
"Runtime": "nodejs18.x"
51+
},
52+
"DependsOn": [
53+
"NodeJsFunctionServiceRole9AE046B6"
54+
]
55+
}
56+
},
57+
"Parameters": {
58+
"BootstrapVersion": {
59+
"Type": "AWS::SSM::Parameter::Value<String>",
60+
"Default": "/cdk-bootstrap/hnb659fds/version",
61+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
62+
}
63+
},
64+
"Rules": {
65+
"CheckBootstrapVersion": {
66+
"Assertions": [
67+
{
68+
"Assert": {
69+
"Fn::Not": [
70+
{
71+
"Fn::Contains": [
72+
[
73+
"1",
74+
"2",
75+
"3",
76+
"4",
77+
"5"
78+
],
79+
{
80+
"Ref": "BootstrapVersion"
81+
}
82+
]
83+
}
84+
]
85+
},
86+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
87+
}
88+
]
89+
}
90+
}
91+
}

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.function-exclude-smithy-models.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-lambda-nodejs/test/integ.function-exclude-smithy-models.js.snapshot/integ.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)