Skip to content

Commit

Permalink
fix(cloudfront): truncate long ResponseHeaderPolicy names (aws#21525)
Browse files Browse the repository at this point in the history
Fixes aws#21524

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.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
blimmer authored and josephedward committed Aug 30, 2022
1 parent 76bcae2 commit 09116dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export class ResponseHeadersPolicy extends Resource implements IResponseHeadersP
physicalName: props.responseHeadersPolicyName,
});

const responseHeadersPolicyName = props.responseHeadersPolicyName ?? Names.uniqueId(this);
const responseHeadersPolicyName = props.responseHeadersPolicyName ?? Names.uniqueResourceName(this, {
maxLength: 128,
});

const resource = new CfnResponseHeadersPolicy(this, 'Resource', {
responseHeadersPolicyConfig: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,14 @@ describe('ResponseHeadersPolicy', () => {
},
});
});

test('it truncates long auto-generated names', () => {
new ResponseHeadersPolicy(stack, 'AVeryLongIdThatMightSeemRidiculousButSometimesHappensInCdkPipelinesBecauseTheStageNamesConcatenatedWithTheRegionAreQuiteLongMuchLongerThanYouWouldExpect');

Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::ResponseHeadersPolicy', {
ResponseHeadersPolicyConfig: {
Name: 'StackAVeryLongIdThatMightSeemRidiculousButSometimesHappensIntenatedWithTheRegionAreQuiteLongMuchLongerThanYouWouldExpect39083892',
},
});
});
});

0 comments on commit 09116dc

Please sign in to comment.