Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(cloudfront): Name length of cache policy #23272

Open
jnawk opened this issue Dec 8, 2022 · 2 comments
Open

(cloudfront): Name length of cache policy #23272

jnawk opened this issue Dec 8, 2022 · 2 comments
Assignees
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@jnawk
Copy link

jnawk commented Dec 8, 2022

Describe the bug

When introducing an unnamed CachePolicy to a CloudFront distribution which is deeply nested in constructs the automatic generated name could grow beyond 128 characters, in spite of #18918 / #18953. This will cause the CDK to raise an exception

Expected Behavior

CDK is able to figure out how to make a properly unique policy name without raising exceptions

Current Behavior

CDK is unable to figure out how to make a properly unique policy name without raising exceptions.

In the reproduction case, the offending policy's id is a single character, which is still too long.

Reproduction Steps

Attempt to synth the project that can be cloned from here: https://github.com/jnawk/cdk-cfront-policy-name-too-long

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.54.0

Framework Version

2.54.0

Node.js Version

16.18.1

OS

Ubuntu 22.04.1 LTS

Language

Typescript

Language Version

TS4.9.4

Other information

No response

@jnawk jnawk added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 8, 2022
@github-actions github-actions bot added the @aws-cdk/aws-cloudfront Related to Amazon CloudFront label Dec 8, 2022
@khushail khushail self-assigned this Dec 8, 2022
@khushail khushail added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Dec 8, 2022
@khushail khushail removed their assignment Dec 9, 2022
@khushail khushail removed the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Dec 9, 2022
@peterwoodworth
Copy link
Contributor

peterwoodworth commented Dec 10, 2022

Thanks for reporting this, the PR looks like it should have fixed this issue. A little bit of investigating reveals that the generated name should be 128 or fewer characters:

const cachePolicyName = props.cachePolicyName ?? `${Names.uniqueId(this).slice(0, 110)}-${Stack.of(this).region}`;

The name should be 110 + - + the region name, which would become a max of length 125 given the regions with the longest names are 14 characters. However, the synth time check is failing because Stack.of(this).region doesn't return a the actual region value, but rather a token like ${Token[AWS.Region.4]} which can be 22-23 characters long.

We will have to further modify this check to account for the fact that the region will be a token value, and thus longer.

In the meantime you can supply your own cachePolicyName when creating this construct to work around the autogenerating bug

@peterwoodworth peterwoodworth added p2 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Dec 10, 2022
@grrapport
Copy link

I ran into the same issue with a Lambda Layer- the name is too long in the regions with longer names. Specifically, the same stack worked in us-east-1, but failed in ap-southeast-1.

Like the above example, it's nested a couple constructs deep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

No branches or pull requests

5 participants