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

aws-cdk-lib.aws_globalaccelerator: Name attribute not generated according to rules #24325

Closed
nakedible-p opened this issue Feb 24, 2023 · 2 comments · Fixed by #24796
Closed
Labels
aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@nakedible-p
Copy link
Contributor

Describe the bug

It seems that the Accelerator "Name" attribute is generated incorrectly and cause errors that prevent the creation of the accelerator if the automatically generated name is too long.

Expected Behavior

I expected the resource to be created successfully and with a compliant name.

Current Behavior

The error message returned was:

Resource handler returned message: "Model validation failed (#/Name: 2 schema violations found) #/Name: expected maxLength: 64, actual: 68 (#/Name) #/Name: failed validation constraint for keyword [pattern] (#/Name)" (RequestToken: e4dc2c84-20e3-c18e-d9b1-649ca1fe3a1e, HandlerErrorCode: InvalidRequest)

Reproduction Steps

I have a stack named ZpayGlobalSyteCentral-Stack and an accelerator named Accelerator.

    const accelerator = new Accelerator(this, 'Accelerator');
    pipeline.addStage(new ZpayGlobalStage(this, 'NpayGlobalSyteCentral', {

The generated unique name is 68 characters long, where as 64 characters is the limit for a GlobalAccelerator name.

Possible Solution

It seems that the current name is generated by cdk.Names.uniqueId:

name: props.acceleratorName ?? cdk.Names.uniqueId(this),

This is incorrect to generate a resource name, as explained by the documentation. Instead, the generation should happen via cdk.Names.uniqueResourceName:

      name: props.acceleratorName ?? cdk.Names.uniqueResourceName(this, { maxLength: 64, allowedSpecialCharacters: '.-' }),

Above code is not tested and is not a significant contribution from me, so can be used freely and without attribution.

Additional Information/Context

https://i.imgur.com/MS1ysj0.mp4

CDK CLI Version

2.66.0 (build c96c17d)

Framework Version

No response

Node.js Version

v19.5.0

OS

Linux codespaces-af5ba0 5.4.0-1103-azure #109~18.04.1-Ubuntu SMP Wed Jan 25 20:53:00 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Language

Typescript

Language Version

4.9.5

Other information

No response

@nakedible-p nakedible-p added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 24, 2023
@github-actions github-actions bot added the aws-cdk-lib Related to the aws-cdk-lib package label Feb 24, 2023
@pahud
Copy link
Contributor

pahud commented Feb 24, 2023

Thank you for your report. Yes you are right we should use cdk.Names.uniqueResourceName() instead. I am making this p2 bug and I will discuss with the core team if we can fix it without breaking changes given this model has been stable.

@pahud pahud 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 Feb 24, 2023
lpizzinidev added a commit to lpizzinidev/aws-cdk that referenced this issue Mar 30, 2023
lpizzinidev added a commit to lpizzinidev/aws-cdk that referenced this issue Apr 4, 2023
mergify bot added a commit to lpizzinidev/aws-cdk that referenced this issue Apr 4, 2023
@mergify mergify bot closed this as completed in #24796 Apr 4, 2023
mergify bot pushed a commit that referenced this issue Apr 4, 2023
…ers (#24796)

The global accelerator should automatically generate a Name with a length smaller than 64 characters if the `acceleratorName` property is not specified, otherwise, it will fail during synth.
If `acceleratorName` is specified, it should validate its length to be in the expected range (1-64 characters).

Closes #24325.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Apr 4, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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

Successfully merging a pull request may close this issue.

2 participants