Skip to content

Commit

Permalink
feat: add naming convention check
Browse files Browse the repository at this point in the history
  • Loading branch information
badmintoncryer committed Dec 22, 2023
1 parent 6824513 commit ef8e34f
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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. 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
Original file line number Diff line number Diff line change
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. The name must only include lowercase letters, numbers, underscores, hyphens, and must not exceed 64 characters.');
});

0 comments on commit ef8e34f

Please sign in to comment.