Skip to content

Commit 00331a7

Browse files
authored
fix(lambda-python-alpha): bundling hash logic includes auth tokens in PIP urls, causing an unnecessary rebuild (#27903)
Update the bundler hash logic to ignore the secret token that is included in the URL when fetching packages from Code Artifact. This token changes constantly, and prevents the results of a previous build from being reused, along with causing lambdas to be unnecessarily redeployed anytime the CDK is built, even if no code is changed. This implementation strips the token from the hash, but does not change anything else about the hash. Open question Currently this logic will error if an invalid URL string is passed for PIP_INDEX_URL or PIP_EXTRA_INDEX_URL. The build would fail later anyway when those URLs are being used, but I'm happy to try/catch this logic block to be more robust if that is preferred. Closes #27331. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 84d81b6 commit 00331a7

File tree

13 files changed

+34188
-1291
lines changed

13 files changed

+34188
-1291
lines changed

packages/@aws-cdk/aws-lambda-python-alpha/test/integ.function.js.snapshot/asset.73c20a669c041469f7fc3fc03d574b093b5b97e7c716f76c1e8117e6163e4dc4.bundle/index.js

-1,205
This file was deleted.

packages/@aws-cdk/aws-lambda-python-alpha/test/integ.function.js.snapshot/asset.a5feac1d1e65b04919886f5961fd2ba1352489d558439d9d6592877e92fc2814.bundle/index.js

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

packages/@aws-cdk/aws-lambda-python-alpha/test/integ.function.js.snapshot/cdk.out

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

packages/@aws-cdk/aws-lambda-python-alpha/test/integ.function.js.snapshot/integ-lambda-python-function.assets.json

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

packages/@aws-cdk/aws-lambda-python-alpha/test/integ.function.js.snapshot/integ-lambda-python-function.template.json

+73-4
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
"S3Bucket": {
3939
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
4040
},
41-
"S3Key": "74aba657619dfbc372ad5df5cf98a022a4322098a338ee81683de7c8d01d4664.zip"
41+
"S3Key": "130f332ecdd8088282adfd41a4353e2fb2951c24281cd5f91470230f6b82841f.zip"
4242
},
43+
"Handler": "index.handler",
4344
"Role": {
4445
"Fn::GetAtt": [
4546
"myhandlerServiceRole77891068",
4647
"Arn"
4748
]
4849
},
49-
"Handler": "index.handler",
5050
"Runtime": "python3.9"
5151
},
5252
"DependsOn": [
@@ -91,20 +91,73 @@
9191
"S3Bucket": {
9292
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
9393
},
94-
"S3Key": "8e8d2a8b3838f7d231d348e1c27c9f8e682c8dd4ff9af71d88795db2009a6d51.zip"
94+
"S3Key": "f425d7725431bdf99c0da5f07fb530e0dd3d8fcaef1a105adfc15e05c0670d2c.zip"
9595
},
96+
"Handler": "index.handler",
9697
"Role": {
9798
"Fn::GetAtt": [
9899
"myhandlerexcludesServiceRoleBB475DCC",
99100
"Arn"
100101
]
101102
},
102-
"Handler": "index.handler",
103103
"Runtime": "python3.9"
104104
},
105105
"DependsOn": [
106106
"myhandlerexcludesServiceRoleBB475DCC"
107107
]
108+
},
109+
"myhandlerpypiServiceRoleF3CDF4F9": {
110+
"Type": "AWS::IAM::Role",
111+
"Properties": {
112+
"AssumeRolePolicyDocument": {
113+
"Statement": [
114+
{
115+
"Action": "sts:AssumeRole",
116+
"Effect": "Allow",
117+
"Principal": {
118+
"Service": "lambda.amazonaws.com"
119+
}
120+
}
121+
],
122+
"Version": "2012-10-17"
123+
},
124+
"ManagedPolicyArns": [
125+
{
126+
"Fn::Join": [
127+
"",
128+
[
129+
"arn:",
130+
{
131+
"Ref": "AWS::Partition"
132+
},
133+
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
134+
]
135+
]
136+
}
137+
]
138+
}
139+
},
140+
"myhandlerpypiBADBA141": {
141+
"Type": "AWS::Lambda::Function",
142+
"Properties": {
143+
"Code": {
144+
"S3Bucket": {
145+
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
146+
},
147+
"S3Key": "e1453d72dc45873ddf9323c37715423413cdfd3506485238f1f9ce965a3b2d2e.zip"
148+
},
149+
"Handler": "index.handler",
150+
"Role": {
151+
"Fn::GetAtt": [
152+
"myhandlerpypiServiceRoleF3CDF4F9",
153+
"Arn"
154+
]
155+
},
156+
"Runtime": "python3.9"
157+
},
158+
"DependsOn": [
159+
"myhandlerpypiServiceRoleF3CDF4F9"
160+
]
108161
}
109162
},
110163
"Outputs": {
@@ -124,6 +177,14 @@
124177
]
125178
}
126179
},
180+
"functionWithCustomPypi": {
181+
"Value": {
182+
"Fn::GetAtt": [
183+
"myhandlerpypiBADBA141",
184+
"Arn"
185+
]
186+
}
187+
},
127188
"ExportsOutputRefmyhandlerD202FA8E369E8804": {
128189
"Value": {
129190
"Ref": "myhandlerD202FA8E"
@@ -139,6 +200,14 @@
139200
"Export": {
140201
"Name": "integ-lambda-python-function:ExportsOutputRefmyhandlerexcludes0437E0D23D81F234"
141202
}
203+
},
204+
"ExportsOutputRefmyhandlerpypiBADBA141A80E83F9": {
205+
"Value": {
206+
"Ref": "myhandlerpypiBADBA141"
207+
},
208+
"Export": {
209+
"Name": "integ-lambda-python-function:ExportsOutputRefmyhandlerpypiBADBA141A80E83F9"
210+
}
142211
}
143212
},
144213
"Parameters": {

packages/@aws-cdk/aws-lambda-python-alpha/test/integ.function.js.snapshot/integ.json

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

packages/@aws-cdk/aws-lambda-python-alpha/test/integ.function.js.snapshot/lambdapythonfunctionDefaultTestDeployAssertC9C6EE6F.assets.json

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

0 commit comments

Comments
 (0)