diff --git a/packages/aws-cdk-lib/core/lib/private/logical-id.ts b/packages/aws-cdk-lib/core/lib/private/logical-id.ts index 1a9051ebb1790..f7ac42990252b 100644 --- a/packages/aws-cdk-lib/core/lib/private/logical-id.ts +++ b/packages/aws-cdk-lib/core/lib/private/logical-id.ts @@ -69,7 +69,7 @@ export class LogicalIDs { } } -const VALID_LOGICALID_REGEX = /^[A-Za-z][A-Za-z0-9]{1,254}$/; +const VALID_LOGICALID_REGEX = /^[A-Za-z0-9]{1,255}$/; /** * Validate logical ID is valid for CloudFormation diff --git a/packages/aws-cdk-lib/core/test/logical-id.test.ts b/packages/aws-cdk-lib/core/test/logical-id.test.ts index 2edc32d6120c4..df34ddb8d5fcf 100644 --- a/packages/aws-cdk-lib/core/test/logical-id.test.ts +++ b/packages/aws-cdk-lib/core/test/logical-id.test.ts @@ -161,6 +161,25 @@ describe('logical id', () => { expect(() => toCloudFormation(stack)).toThrow(/Logical ID must adhere to the regular expression/); }); + test('any alphaneumeric logical id is allowed', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const validLogicalIdAlpha = generateString(200); + const validLogicalIdNumber = generateNumberString(200); + new CfnResource(stack, validLogicalIdAlpha, { type: 'R' }); + new CfnResource(stack, validLogicalIdNumber, { type: 'R' } ); + + // THEN + expect(toCloudFormation(stack)).toEqual({ + Resources: { + [validLogicalIdAlpha]: { Type: 'R' }, + [validLogicalIdNumber]: { Type: 'R' }, + }, + }); + }); + test('too large identifiers are truncated yet still remain unique', () => { // GIVEN const stack = new Stack(); @@ -253,7 +272,13 @@ describe('logical id', () => { }).toThrow(/section 'Resources' already contains 'C'/); }); }); - +function generateNumberString(chars: number) { + let s = ''; + for (let i = 0; i < chars; ++i) { + s += Math.floor(Math.random() * 9); + } + return s; +} function generateString(chars: number) { let s = ''; for (let i = 0; i < chars; ++i) {