From be6ddb88cce057ef23ff8fee67a4f5b3f063a931 Mon Sep 17 00:00:00 2001 From: kazuho cryer-shinozuka Date: Sat, 23 Dec 2023 08:01:48 +0900 Subject: [PATCH] feat(ses): synth-time naming validation for dedicatedIpPoolName (#28466) This Pull Request introduces a new validation feature to the DedicatedIpPoolProps. It ensures that the dedicatedIpPoolName adheres to the specified naming conventions, enhancing data integrity and preventing runtime errors due to invalid names. Closes #28451 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- 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..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 @@ -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 "${props.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..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 @@ -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 "invalidName". The name must only include lowercase letters, numbers, underscores, hyphens, and must not exceed 64 characters.'); +});