Skip to content

core: logical ID validation regex is inconsistant with cloudformation specification #26075

@ashwin300

Description

@ashwin300

Describe the bug

The CloudFormation documentation indicates that logical ID's must be only alphanumeric, yet the regex in the logical ID validation file is /^[A-Za-z][A-Za-z0-9]{1,254}$/. This causes logical IDs such as 030ffab42b5f448fb39750B452 to fail even though they are valid according to the CloudFormation standard.

Expected Behavior

Logical IDs such as 030ffab42b5f448fb39750B452 to be considered valid to the CDK when synthesizing a stack

Current Behavior

Logical IDs such as 030ffab42b5f448fb39750B452 are not considered valid when synthesizing a stack.

Error: Resolution error: Logical ID must adhere to the regular expression: /^[A-Za-z][A-Za-z0-9]{1,254}$/, got '030ffab42b5f448fb39750B452'.

Reproduction Steps

  1. initialize sample cdk app
  2. in the stack, add the following code:
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as sqs from 'aws-cdk-lib/aws-sqs';

export class CdkErrorTestStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    // The code that defines your stack goes here

    // example resource
    const queue = new sqs.Queue(this, '030ffab42b5f448fb39750B452', {
      visibilityTimeout: cdk.Duration.seconds(300)
    });
  }
}

run cdk synth

Possible Solution

Change the logical ID validation regex to fit CloudFormation documentation, or change the documentation to reflect the regex validation.

Additional Information/Context

No response

CDK CLI Version

2.85.0 (build 4e0d726)

Framework Version

No response

Node.js Version

v14.21.3

OS

Linux

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/coreRelated to core CDK functionalitybugThis issue is a bug.effort/smallSmall work item – less than a day of effortgood first issueRelated to contributions. See CONTRIBUTING.mdp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions