Skip to content

Commit 450f7ca

Browse files
authoredDec 10, 2021
fix(cognito): remove invalid SES region check (#17868)
When configuring the Cognito SES email integration we were performing a region check to make sure you were configuring SES in one of the 3 supported regions. This was based on the Cognito documentation [here](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-email.html#user-pool-email-developer) which is not correct. This PR removes that check allowing CloudFormation to provide the validation. If a user provides an incorrect region the CloudFormation deployment will fail with a descriptive error message. fixes #17795 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 42cf186 commit 450f7ca

File tree

3 files changed

+1
-52
lines changed

3 files changed

+1
-52
lines changed
 

‎packages/@aws-cdk/aws-cognito/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ new cognito.UserPool(this, 'myuserpool', {
349349
});
350350
```
351351

352-
Sending emails through SES requires that SES be configured (as described above) in one of the regions - `us-east-1`, `us-west-1`, or `eu-west-1`.
352+
Sending emails through SES requires that SES be configured (as described above) in a valid SES region.
353353
If the UserPool is being created in a different region, `sesRegion` must be used to specify the correct SES region.
354354

355355
```ts

‎packages/@aws-cdk/aws-cognito/lib/user-pool-email.ts

-11
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ import { Stack, Token } from '@aws-cdk/core';
22
import { Construct } from 'constructs';
33
import { toASCII as punycodeEncode } from 'punycode/';
44

5-
/**
6-
* The valid Amazon SES configuration regions
7-
*/
8-
const REGIONS = ['us-east-1', 'us-west-2', 'eu-west-1'];
9-
105
/**
116
* Configuration for Cognito sending emails via Amazon SES
127
*/
@@ -164,12 +159,6 @@ class SESEmail extends UserPoolEmail {
164159
throw new Error('Your stack region cannot be determined so "sesRegion" is required in SESOptions');
165160
}
166161

167-
if (this.options.sesRegion && !REGIONS.includes(this.options.sesRegion)) {
168-
throw new Error(`sesRegion must be one of 'us-east-1', 'us-west-2', 'eu-west-1'. received ${this.options.sesRegion}`);
169-
} else if (!this.options.sesRegion && !REGIONS.includes(region)) {
170-
throw new Error(`Your stack is in ${region}, which is not a SES Region. Please provide a valid value for 'sesRegion'`);
171-
}
172-
173162
let from = this.options.fromEmail;
174163
if (this.options.fromName) {
175164
from = `${this.options.fromName} <${this.options.fromEmail}>`;

‎packages/@aws-cdk/aws-cognito/test/user-pool.test.ts

-40
Original file line numberDiff line numberDiff line change
@@ -1701,48 +1701,8 @@ describe('User Pool', () => {
17011701
},
17021702
});
17031703

1704-
});
1705-
test('email withSES invalid region throws error', () => {
1706-
// GIVEN
1707-
const stack = new Stack(undefined, undefined, {
1708-
env: {
1709-
region: 'us-east-2',
1710-
account: '11111111111',
1711-
},
1712-
});
1713-
1714-
// WHEN
1715-
expect(() => new UserPool(stack, 'Pool', {
1716-
email: UserPoolEmail.withSES({
1717-
fromEmail: 'mycustomemail@example.com',
1718-
fromName: 'My Custom Email',
1719-
replyTo: 'reply@example.com',
1720-
configurationSetName: 'default',
1721-
}),
1722-
})).toThrow(/Please provide a valid value/);
1723-
17241704
});
17251705

1726-
test('email withSES invalid sesRegion throws error', () => {
1727-
// GIVEN
1728-
const stack = new Stack(undefined, undefined, {
1729-
env: {
1730-
account: '11111111111',
1731-
},
1732-
});
1733-
1734-
// WHEN
1735-
expect(() => new UserPool(stack, 'Pool', {
1736-
email: UserPoolEmail.withSES({
1737-
sesRegion: 'us-east-2',
1738-
fromEmail: 'mycustomemail@example.com',
1739-
fromName: 'My Custom Email',
1740-
replyTo: 'reply@example.com',
1741-
configurationSetName: 'default',
1742-
}),
1743-
})).toThrow(/sesRegion must be one of/);
1744-
1745-
});
17461706
});
17471707

17481708
test('device tracking is configured correctly', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.