Skip to content

Commit

Permalink
fix(cloudfront): make long function name deterministic (#30392)
Browse files Browse the repository at this point in the history
### 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*
  • Loading branch information
Leo10Gama authored Jun 11, 2024
1 parent 1d93094 commit e19d18b
Show file tree
Hide file tree
Showing 18 changed files with 270 additions and 64 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"AutoPublish": true,
"FunctionCode": "function handler(event) { return event.request }",
"FunctionConfig": {
"Comment": "eu-west-1integdistributionfunctionFunctionRequest8E65DEEB",
"Comment": "eu-west-1integ-distributinFunctionRequest8E65DEEB",
"Runtime": "cloudfront-js-1.0"
},
"Name": "eu-west-1integdistributionfunctionFunctionRequest8E65DEEB"
"Name": "eu-west-1integ-distributinFunctionRequest8E65DEEB"
}
},
"FunctionResponse4EF2D1D3": {
Expand All @@ -18,10 +18,10 @@
"AutoPublish": true,
"FunctionCode": "function handler(event) { return event.response }",
"FunctionConfig": {
"Comment": "eu-west-1integdistributionfunctionFunctionResponseDD4BADA1",
"Comment": "eu-west-1integ-distributiFunctionResponseDD4BADA1",
"Runtime": "cloudfront-js-2.0"
},
"Name": "eu-west-1integdistributionfunctionFunctionResponseDD4BADA1"
"Name": "eu-west-1integ-distributiFunctionResponseDD4BADA1"
}
},
"DistB3B78991": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"Function76856677": {
"Type": "AWS::CloudFront::Function",
"Properties": {
"Name": "eu-west-1integdistributionfunctionFunctionDCD62A02",
"AutoPublish": true,
"FunctionCode": "function handler(event) { return event.request }",
"FunctionConfig": {
"Comment": "eu-west-1integdistributionfunctionFunctionDCD62A02",
"Runtime": "cloudfront-js-1.0"
}
},
"Name": "eu-west-1integdistributionfunctionFunctionDCD62A02"
}
},
"DistB3B78991": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e19d18b

Please sign in to comment.