Skip to content

Commit be6ddb8

Browse files
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*
1 parent 7635bbc commit be6ddb8

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

packages/aws-cdk-lib/aws-ses/README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,19 @@ When you create a new Amazon SES account, your emails are sent from IP addresses
111111
Amazon SES users. For [an additional monthly charge](https://aws.amazon.com/ses/pricing/), you can lease
112112
dedicated IP addresses that are reserved for your exclusive use.
113113

114-
Use the `DedicatedIpPool` construct to create a pool of dedicated IP addresses:
114+
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:
115+
116+
- The name must include only lowercase letters (a-z), numbers (0-9), underscores (_), and hyphens (-).
117+
- The name must not exceed 64 characters in length.
115118

116119
```ts
117120
new ses.DedicatedIpPool(this, 'Pool', {
121+
dedicatedIpPoolName: 'mypool',
118122
scalingMode: ses.ScalingMode.STANDARD,
119123
});
120124
```
121125

122-
The pool can then be used in a configuration set.
126+
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.
123127

124128
### Configuration sets
125129

packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export interface DedicatedIpPoolProps {
3838
/**
3939
* A name for the dedicated IP pool.
4040
*
41+
* The name must adhere to specific constraints: it can only include
42+
* lowercase letters (a-z), numbers (0-9), underscores (_), and hyphens (-),
43+
* and must not exceed 64 characters in length.
44+
*
4145
* @default - a CloudFormation generated name
4246
*/
4347
readonly dedicatedIpPoolName?: string;
@@ -74,6 +78,10 @@ export class DedicatedIpPool extends Resource implements IDedicatedIpPool {
7478
physicalName: props.dedicatedIpPoolName,
7579
});
7680

81+
if (props.dedicatedIpPoolName && !/^[a-z0-9_-]{0,64}$/.test(props.dedicatedIpPoolName)) {
82+
throw new Error(`Invalid dedicatedIpPoolName "${props.dedicatedIpPoolName}". The name must only include lowercase letters, numbers, underscores, hyphens, and must not exceed 64 characters.`);
83+
}
84+
7785
const pool = new CfnDedicatedIpPool(this, 'Resource', {
7886
poolName: this.physicalName,
7987
scalingMode: props.scalingMode,

packages/aws-cdk-lib/aws-ses/test/dedicated-ip-pool.test.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,11 @@ test('dedicated IP pool with scailingMode', () => {
2626
PoolName: Match.absent(),
2727
ScalingMode: 'MANAGED',
2828
});
29-
});
29+
});
30+
31+
test('dedicated IP pool with invalid name', () => {
32+
// THEN
33+
expect(() => new DedicatedIpPool(stack, 'Pool', {
34+
dedicatedIpPoolName: 'invalidName',
35+
})).toThrow('Invalid dedicatedIpPoolName "invalidName". The name must only include lowercase letters, numbers, underscores, hyphens, and must not exceed 64 characters.');
36+
});

0 commit comments

Comments
 (0)