From d96042d378ebb5e4ca3c153dd8b0cebf6bae80eb Mon Sep 17 00:00:00 2001 From: maz Date: Mon, 29 Jul 2024 23:54:24 +0900 Subject: [PATCH 1/2] add description validation --- .../aws-location-alpha/lib/place-index.ts | 4 +++ .../test/place-index.test.ts | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/packages/@aws-cdk/aws-location-alpha/lib/place-index.ts b/packages/@aws-cdk/aws-location-alpha/lib/place-index.ts index ae62abe343bea..b0646037355f2 100644 --- a/packages/@aws-cdk/aws-location-alpha/lib/place-index.ts +++ b/packages/@aws-cdk/aws-location-alpha/lib/place-index.ts @@ -175,6 +175,10 @@ export class PlaceIndex extends PlaceIndexBase { public readonly placeIndexUpdateTime: string; constructor(scope: Construct, id: string, props: PlaceIndexProps = {}) { + if (props.description && !Token.isUnresolved(props.description) && props.description.length > 1000) { + throw new Error(`\`description\` must be between 0 and 1000 characters. Received: ${props.description.length} characters`); + } + if (props.placeIndexName && !Token.isUnresolved(props.placeIndexName) && !/^[-.\w]{1,100}$/.test(props.placeIndexName)) { throw new Error(`Invalid place index name. The place index name must be between 1 and 100 characters and contain only alphanumeric characters, hyphens, periods and underscores. Received: ${props.placeIndexName}`); } diff --git a/packages/@aws-cdk/aws-location-alpha/test/place-index.test.ts b/packages/@aws-cdk/aws-location-alpha/test/place-index.test.ts index 763ff44c573f6..a600705339445 100644 --- a/packages/@aws-cdk/aws-location-alpha/test/place-index.test.ts +++ b/packages/@aws-cdk/aws-location-alpha/test/place-index.test.ts @@ -17,6 +17,34 @@ test('create a place index', () => { }); }); +test('create a place index with description', () => { + new PlaceIndex(stack, 'PlaceIndex', { + description: 'my-description', + }); + + Template.fromStack(stack).hasResourceProperties('AWS::Location::PlaceIndex', { + DataSource: 'Esri', + IndexName: 'PlaceIndex', + Description: 'my-description', + }); +}); + +test('creates a place index with empty description', () => { + new PlaceIndex(stack, 'PlaceIndex', { + description: '', + }); + + Template.fromStack(stack).hasResourceProperties('AWS::Location::PlaceIndex', { + Description: '', + }); +}); + +test('throws with invalid description', () => { + expect(() => new PlaceIndex(stack, 'PlaceIndex', { + description: 'a'.repeat(1001), + })).toThrow('`description` must be between 0 and 1000 characters. Received: 1001 characters'); +}); + test('throws with invalid name', () => { expect(() => new PlaceIndex(stack, 'PlaceIndex', { placeIndexName: 'inv@lid', From 252d7cce852dcee399fedbff625a6a1308b65780 Mon Sep 17 00:00:00 2001 From: maz Date: Thu, 1 Aug 2024 00:07:08 +0900 Subject: [PATCH 2/2] update docs --- packages/@aws-cdk/aws-location-alpha/lib/place-index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/@aws-cdk/aws-location-alpha/lib/place-index.ts b/packages/@aws-cdk/aws-location-alpha/lib/place-index.ts index b0646037355f2..144059b6469a2 100644 --- a/packages/@aws-cdk/aws-location-alpha/lib/place-index.ts +++ b/packages/@aws-cdk/aws-location-alpha/lib/place-index.ts @@ -29,6 +29,9 @@ export interface PlaceIndexProps { /** * A name for the place index * + * Must be between 1 and 100 characters and contain only alphanumeric characters, + * hyphens, periods and underscores. + * * @default - A name is automatically generated */ readonly placeIndexName?: string;