From ef8e34f84383091dd56fe3b31e8828cbce6abebe Mon Sep 17 00:00:00 2001 From: Kazuho CryerShinozuka Date: Fri, 22 Dec 2023 22:30:06 +0900 Subject: [PATCH 1/2] feat: add naming convention check --- packages/aws-cdk-lib/aws-ses/README.md | 8 ++++++-- packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts | 8 ++++++++ .../aws-cdk-lib/aws-ses/test/dedicated-ip-pool.test.ts | 9 ++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ses/README.md b/packages/aws-cdk-lib/aws-ses/README.md index 876b8a23edb24..5120aedd90bc8 100644 --- a/packages/aws-cdk-lib/aws-ses/README.md +++ b/packages/aws-cdk-lib/aws-ses/README.md @@ -111,15 +111,19 @@ When you create a new Amazon SES account, your emails are sent from IP addresses Amazon SES users. For [an additional monthly charge](https://aws.amazon.com/ses/pricing/), you can lease dedicated IP addresses that are reserved for your exclusive use. -Use the `DedicatedIpPool` construct to create a pool of dedicated IP addresses: +Use the DedicatedIpPool construct to create a pool of dedicated IP addresses. When specifying a name for your dedicated IP pool, ensure that it adheres to the following naming convention: + +- The name must include only lowercase letters (a-z), numbers (0-9), underscores (_), and hyphens (-). +- The name must not exceed 64 characters in length. ```ts new ses.DedicatedIpPool(this, 'Pool', { + dedicatedIpPoolName: 'mypool', scalingMode: ses.ScalingMode.STANDARD, }); ``` -The pool can then be used in a configuration set. +The pool can then be used in a configuration set. If the provided dedicatedIpPoolName does not follow the specified naming convention, an error will be thrown. ### Configuration sets diff --git a/packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts b/packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts index 42ff4a5f481b3..9c71dbe8dc137 100644 --- a/packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts +++ b/packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts @@ -38,6 +38,10 @@ export interface DedicatedIpPoolProps { /** * A name for the dedicated IP pool. * + * The name must adhere to specific constraints: it can only include + * lowercase letters (a-z), numbers (0-9), underscores (_), and hyphens (-), + * and must not exceed 64 characters in length. + * * @default - a CloudFormation generated name */ readonly dedicatedIpPoolName?: string; @@ -74,6 +78,10 @@ export class DedicatedIpPool extends Resource implements IDedicatedIpPool { physicalName: props.dedicatedIpPoolName, }); + if (props.dedicatedIpPoolName && !/^[a-z0-9_-]{0,64}$/.test(props.dedicatedIpPoolName)) { + throw new Error('Invalid dedicatedIpPoolName. The name must only include lowercase letters, numbers, underscores, hyphens, and must not exceed 64 characters.'); + } + const pool = new CfnDedicatedIpPool(this, 'Resource', { poolName: this.physicalName, scalingMode: props.scalingMode, diff --git a/packages/aws-cdk-lib/aws-ses/test/dedicated-ip-pool.test.ts b/packages/aws-cdk-lib/aws-ses/test/dedicated-ip-pool.test.ts index 82f83ba259ef2..3014c56a87c08 100644 --- a/packages/aws-cdk-lib/aws-ses/test/dedicated-ip-pool.test.ts +++ b/packages/aws-cdk-lib/aws-ses/test/dedicated-ip-pool.test.ts @@ -26,4 +26,11 @@ test('dedicated IP pool with scailingMode', () => { PoolName: Match.absent(), ScalingMode: 'MANAGED', }); -}); \ No newline at end of file +}); + +test('dedicated IP pool with invalid name', () => { + // THEN + expect(() => new DedicatedIpPool(stack, 'Pool', { + dedicatedIpPoolName: 'invalidName', + })).toThrow('Invalid dedicatedIpPoolName. The name must only include lowercase letters, numbers, underscores, hyphens, and must not exceed 64 characters.'); +}); From b9c1f34c77757ea0c222fa35bd20c167169008eb Mon Sep 17 00:00:00 2001 From: Kaizen Conroy <36202692+kaizencc@users.noreply.github.com> Date: Fri, 22 Dec 2023 13:46:36 -0800 Subject: [PATCH 2/2] Apply suggestions from code review --- packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts | 2 +- packages/aws-cdk-lib/aws-ses/test/dedicated-ip-pool.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts b/packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts index 9c71dbe8dc137..166379fa7eeac 100644 --- a/packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts +++ b/packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts @@ -79,7 +79,7 @@ export class DedicatedIpPool extends Resource implements IDedicatedIpPool { }); if (props.dedicatedIpPoolName && !/^[a-z0-9_-]{0,64}$/.test(props.dedicatedIpPoolName)) { - throw new Error('Invalid dedicatedIpPoolName. The name must only include lowercase letters, numbers, underscores, hyphens, and must not exceed 64 characters.'); + throw new Error(`Invalid dedicatedIpPoolName "${props.dedicatedIpPoolName}". The name must only include lowercase letters, numbers, underscores, hyphens, and must not exceed 64 characters.`); } const pool = new CfnDedicatedIpPool(this, 'Resource', { diff --git a/packages/aws-cdk-lib/aws-ses/test/dedicated-ip-pool.test.ts b/packages/aws-cdk-lib/aws-ses/test/dedicated-ip-pool.test.ts index 3014c56a87c08..9ce6dd4f73a48 100644 --- a/packages/aws-cdk-lib/aws-ses/test/dedicated-ip-pool.test.ts +++ b/packages/aws-cdk-lib/aws-ses/test/dedicated-ip-pool.test.ts @@ -32,5 +32,5 @@ test('dedicated IP pool with invalid name', () => { // THEN expect(() => new DedicatedIpPool(stack, 'Pool', { dedicatedIpPoolName: 'invalidName', - })).toThrow('Invalid dedicatedIpPoolName. The name must only include lowercase letters, numbers, underscores, hyphens, and must not exceed 64 characters.'); + })).toThrow('Invalid dedicatedIpPoolName "invalidName". The name must only include lowercase letters, numbers, underscores, hyphens, and must not exceed 64 characters.'); });