Skip to content

aws-synthetics: canary name limit is inconsistent with the API #32376

@regmicmahesh

Description

@regmicmahesh

Describe the bug

When I set the canaryName via cdk code then it says the maximum allowed character is 21. But when I do the same thing on AWS Management Console, I can have upto 255 characters.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

I expected the CDK to have the same limit to the AWS Management Console API.

Current Behavior

I'm getting this error.

Error: Canary name is too large, must be between 1 and 21 characters, but is 29 (got "Generiskinvalid_id_case_12345")

Reproduction Steps

Create a synthetic resource with canaryName string having length of more than 21 characters.

        new aws_synthetics.Canary(this, cdkLogicalId, {
          schedule: aws_synthetics.Schedule.rate(cdk.Duration.minutes(5)),
          canaryName: cdkLogicalId,
          vpc: vpc,
          vpcSubnets: { subnetGroupName: "Private" },
          runtime: aws_synthetics.Runtime.SYNTHETICS_PYTHON_SELENIUM_4_0,
          test: aws_synthetics.Test.custom({
            code: codeAsset,
            handler: `${canaryNameWithoutExt}.handler`,
          }),
          timeout: cdk.Duration.minutes(1),
          startAfterCreation: false,
        });
      });

Possible Solution

function validateName(name: string) {
if (name.length > 21) {
throw new Error(`Canary name is too large, must be between 1 and 21 characters, but is ${name.length} (got "${name}")`);
}
if (!nameRegex.test(name)) {
throw new Error(`Canary name must be lowercase, numbers, hyphens, or underscores (got "${name}")`);
}

In this file, we should update the comparison to be length > 255.

Additional Information/Context

No response

CDK CLI Version

2.162.1 (build 10aa526)

Framework Version

No response

Node.js Version

v18.18.2

OS

Terminal

Language

TypeScript

Language Version

"aws-cdk-lib": "^2.171.0"

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-syntheticsRelated to Amazon CloudWatch SyntheticsbugThis 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