Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ses): synth-time naming validation for dedicatedIpPoolName #28466

Merged
merged 3 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 "${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
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 "invalidName". The name must only include lowercase letters, numbers, underscores, hyphens, and must not exceed 64 characters.');
});