Skip to content

Commit 6eb775e

Browse files
feat(cognito): configure SNS region for UserPool SMS messages (#19519)
fixes #19434 updated integ test domain value, because old value was [failing deployment](aws-samples/aws-cdk-examples#402) ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [x] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 5c223e7 commit 6eb775e

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

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

+10
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,14 @@ export interface UserPoolProps {
522522
*/
523523
readonly smsRoleExternalId?: string;
524524

525+
/**
526+
* The region to integrate with SNS to send SMS messages
527+
*
528+
* This property will do nothing if SMS configuration is not configured
529+
* @default - The same region as the user pool, with a few exceptions - https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-sms-settings.html#user-pool-sms-settings-first-time
530+
*/
531+
readonly snsRegion?: string;
532+
525533
/**
526534
* Setting this would explicitly enable or disable SMS role creation.
527535
* When left unspecified, CDK will determine based on other properties if a role is needed or not.
@@ -1032,6 +1040,7 @@ export class UserPool extends UserPoolBase {
10321040
return {
10331041
snsCallerArn: props.smsRole.roleArn,
10341042
externalId: props.smsRoleExternalId,
1043+
snsRegion: props.snsRegion,
10351044
};
10361045
}
10371046

@@ -1072,6 +1081,7 @@ export class UserPool extends UserPoolBase {
10721081
return {
10731082
externalId: smsRoleExternalId,
10741083
snsCallerArn: smsRole.roleArn,
1084+
snsRegion: props.snsRegion,
10751085
};
10761086
}
10771087

packages/@aws-cdk/aws-cognito/test/integ.user-pool-explicit-props.expected.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,9 @@
833833
"myuserpoolsmsRole0E16FDD9",
834834
"Arn"
835835
]
836+
},
837+
"SnsRegion": {
838+
"Ref": "AWS::Region"
836839
}
837840
},
838841
"SmsVerificationMessage": "verification sms message from the integ test. Code is {####}.",
@@ -850,7 +853,7 @@
850853
"myuserpoolmyuserpooldomainEE1E11AF": {
851854
"Type": "AWS::Cognito::UserPoolDomain",
852855
"Properties": {
853-
"Domain": "myawesomeapp",
856+
"Domain": "cdkintegrationtestuserpoolexplicitprops",
854857
"UserPoolId": {
855858
"Ref": "myuserpool01998219"
856859
}

packages/@aws-cdk/aws-cognito/test/integ.user-pool-explicit-props.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ const userpool = new UserPool(stack, 'myuserpool', {
6969
userMigration: dummyTrigger('userMigration'),
7070
verifyAuthChallengeResponse: dummyTrigger('verifyAuthChallengeResponse'),
7171
},
72+
snsRegion: Stack.of(stack).region,
7273
});
7374

7475
const cognitoDomain = userpool.addDomain('myuserpooldomain', {
7576
cognitoDomain: {
76-
domainPrefix: 'myawesomeapp',
77+
domainPrefix: 'cdkintegrationtestuserpoolexplicitprops',
7778
},
7879
});
7980

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

+22
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,28 @@ describe('User Pool', () => {
235235
});
236236
});
237237

238+
test('snsRegion property is recognized', () => {
239+
// GIVEN
240+
const stack = new Stack();
241+
const role = Role.fromRoleArn(stack, 'smsRole', 'arn:aws:iam::664773442901:role/sms-role');
242+
243+
// WHEN
244+
new UserPool(stack, 'Pool', {
245+
smsRole: role,
246+
smsRoleExternalId: 'test-external-id',
247+
snsRegion: 'test-region-1',
248+
});
249+
250+
// THEN
251+
Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', {
252+
SmsConfiguration: {
253+
ExternalId: 'test-external-id',
254+
SnsCallerArn: role.roleArn,
255+
SnsRegion: 'test-region-1',
256+
},
257+
});
258+
});
259+
238260
test('import using id', () => {
239261
// GIVEN
240262
const stack = new Stack(undefined, undefined, {

0 commit comments

Comments
 (0)