Skip to content

Commit

Permalink
feat(ses): synth-time naming validation for dedicatedIpPoolName (#28466)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
badmintoncryer committed Dec 22, 2023
1 parent 7635bbc commit be6ddb8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/aws-cdk-lib/aws-ses/README.md
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion packages/aws-cdk-lib/aws-ses/test/dedicated-ip-pool.test.ts
Expand Up @@ -26,4 +26,11 @@ test('dedicated IP pool with scailingMode', () => {
PoolName: Match.absent(),
ScalingMode: 'MANAGED',
});
});
});

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.');
});

0 comments on commit be6ddb8

Please sign in to comment.