diff --git a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts index 39bdb24eca355..ef4fa18d809c9 100644 --- a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts +++ b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts @@ -493,7 +493,11 @@ export interface OnImageScanCompletedOptions extends events.OnEventOptions { export interface RepositoryProps { /** - * Name for this repository + * Name for this repository. + * + * The repository name must start with a letter and can only contain lowercase letters, numbers, hyphens, underscores, and forward slashes. + * + * > If you specify a name, you cannot perform updates that require replacement of this resource. You can perform updates that require no or some interruption. If you must replace the resource, specify a new name. * * @default Automatically generated name. */ @@ -672,7 +676,7 @@ export class Repository extends RepositoryBase { } const isPatternMatch = /^(?:[a-z0-9]+(?:[._-][a-z0-9]+)*\/)*[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(repositoryName); if (!isPatternMatch) { - errors.push('Repository name must follow the specified pattern: (?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*'); + errors.push('Repository name must start with a letter and can only contain lowercase letters, numbers, hyphens, underscores, periods and forward slashes'); } if (errors.length > 0) { diff --git a/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts b/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts index 32c79d8d16978..002c347688457 100644 --- a/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts +++ b/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts @@ -898,7 +898,7 @@ describe('repository', () => { const expectedErrors = [ `Invalid ECR repository name (value: ${repositoryName})`, 'Repository name must be at least 2 and no more than 256 characters', - 'Repository name must follow the specified pattern: (?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*', + 'Repository name must start with a letter and can only contain lowercase letters, numbers, hyphens, underscores, periods and forward slashes', ].join(EOL); expect(() => new ecr.Repository(stack, 'Repo', { @@ -923,19 +923,19 @@ describe('repository', () => { expect(() => new ecr.Repository(stack, 'Repo1', { repositoryName: 'aAa', - })).toThrow(/must follow the specified pattern/); + })).toThrow('Repository name must start with a letter and can only contain lowercase letters, numbers, hyphens, underscores, periods and forward slashes'); expect(() => new ecr.Repository(stack, 'Repo2', { repositoryName: 'a--a', - })).toThrow(/must follow the specified pattern/); + })).toThrow('Repository name must start with a letter and can only contain lowercase letters, numbers, hyphens, underscores, periods and forward slashes'); expect(() => new ecr.Repository(stack, 'Repo3', { repositoryName: 'a./a-a', - })).toThrow(/must follow the specified pattern/); + })).toThrow('Repository name must start with a letter and can only contain lowercase letters, numbers, hyphens, underscores, periods and forward slashes'); expect(() => new ecr.Repository(stack, 'Repo4', { repositoryName: 'a//a-a', - })).toThrow(/must follow the specified pattern/); + })).toThrow('Repository name must start with a letter and can only contain lowercase letters, numbers, hyphens, underscores, periods and forward slashes'); }); test('return value addToResourcePolicy', () => {