Skip to content

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

@nakedible-p

Description

@nakedible-p

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    aws-cdk-libRelated to the aws-cdk-lib packagebugThis issue is a bug.effort/smallSmall work item – less than a day of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions