Skip to content

Commit e19d18b

Browse files
authored
fix(cloudfront): make long function name deterministic (#30392)
### Issue # (if applicable) Closes #20017 as well as #15523 and #28629 ### Reason for this change Due to the way function names are generated using token strings with either single- or double-digit numbers, longer function names can be truncated differently, leading to inconsistency in generated CloudFormation templates. ### Description of changes To ensure backwards compatibility, if names are longer than 64 characters and use region tokens, if the token uses a single-digit region number, it takes the first **31** characters + the last 32 characters; if the token uses a double-digit region number or otherwise, it takes the first **32** characters + the last 32 characters. This ensures it will always take the same first chunk of the actual function's name. ### Description of how you validated changes A new unit test was added to verify the consistency of function names in the template. ### Checklist - [x] 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 1d93094 commit e19d18b

18 files changed

+270
-64
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-function-runtime.js.snapshot/CF2RuntimeDefaultTestDeployAssertB25F4037.assets.json

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

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-function-runtime.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-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-function-runtime.js.snapshot/integ-distribution-function.assets.json

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

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-function-runtime.js.snapshot/integ-distribution-function.template.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"AutoPublish": true,
77
"FunctionCode": "function handler(event) { return event.request }",
88
"FunctionConfig": {
9-
"Comment": "eu-west-1integdistributionfunctionFunctionRequest8E65DEEB",
9+
"Comment": "eu-west-1integ-distributinFunctionRequest8E65DEEB",
1010
"Runtime": "cloudfront-js-1.0"
1111
},
12-
"Name": "eu-west-1integdistributionfunctionFunctionRequest8E65DEEB"
12+
"Name": "eu-west-1integ-distributinFunctionRequest8E65DEEB"
1313
}
1414
},
1515
"FunctionResponse4EF2D1D3": {
@@ -18,10 +18,10 @@
1818
"AutoPublish": true,
1919
"FunctionCode": "function handler(event) { return event.response }",
2020
"FunctionConfig": {
21-
"Comment": "eu-west-1integdistributionfunctionFunctionResponseDD4BADA1",
21+
"Comment": "eu-west-1integ-distributiFunctionResponseDD4BADA1",
2222
"Runtime": "cloudfront-js-2.0"
2323
},
24-
"Name": "eu-west-1integdistributionfunctionFunctionResponseDD4BADA1"
24+
"Name": "eu-west-1integ-distributiFunctionResponseDD4BADA1"
2525
}
2626
},
2727
"DistB3B78991": {

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-function-runtime.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-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-function-runtime.js.snapshot/manifest.json

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

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-function-runtime.js.snapshot/tree.json

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

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-function.js.snapshot/DistributionFunctionDefaultTestDeployAssert9D427BC1.assets.json

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

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-function.js.snapshot/DistributionFunctionDefaultTestDeployAssert9D427BC1.template.json

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

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-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-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-function.js.snapshot/integ-distribution-function.assets.json

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

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-function.js.snapshot/integ-distribution-function.template.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"Function76856677": {
44
"Type": "AWS::CloudFront::Function",
55
"Properties": {
6-
"Name": "eu-west-1integdistributionfunctionFunctionDCD62A02",
76
"AutoPublish": true,
87
"FunctionCode": "function handler(event) { return event.request }",
98
"FunctionConfig": {
109
"Comment": "eu-west-1integdistributionfunctionFunctionDCD62A02",
1110
"Runtime": "cloudfront-js-1.0"
12-
}
11+
},
12+
"Name": "eu-west-1integdistributionfunctionFunctionDCD62A02"
1313
}
1414
},
1515
"DistB3B78991": {

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-function.js.snapshot/integ.json

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

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-function.js.snapshot/manifest.json

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

0 commit comments

Comments
 (0)