Skip to content

Commit

Permalink
feat(cognito): configure SNS region for UserPool SMS messages (#19519)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
peterwoodworth authored Mar 28, 2022
1 parent 5c223e7 commit 6eb775e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-cognito/lib/user-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,14 @@ export interface UserPoolProps {
*/
readonly smsRoleExternalId?: string;

/**
* The region to integrate with SNS to send SMS messages
*
* This property will do nothing if SMS configuration is not configured
* @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
*/
readonly snsRegion?: string;

/**
* Setting this would explicitly enable or disable SMS role creation.
* When left unspecified, CDK will determine based on other properties if a role is needed or not.
Expand Down Expand Up @@ -1032,6 +1040,7 @@ export class UserPool extends UserPoolBase {
return {
snsCallerArn: props.smsRole.roleArn,
externalId: props.smsRoleExternalId,
snsRegion: props.snsRegion,
};
}

Expand Down Expand Up @@ -1072,6 +1081,7 @@ export class UserPool extends UserPoolBase {
return {
externalId: smsRoleExternalId,
snsCallerArn: smsRole.roleArn,
snsRegion: props.snsRegion,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,9 @@
"myuserpoolsmsRole0E16FDD9",
"Arn"
]
},
"SnsRegion": {
"Ref": "AWS::Region"
}
},
"SmsVerificationMessage": "verification sms message from the integ test. Code is {####}.",
Expand All @@ -850,7 +853,7 @@
"myuserpoolmyuserpooldomainEE1E11AF": {
"Type": "AWS::Cognito::UserPoolDomain",
"Properties": {
"Domain": "myawesomeapp",
"Domain": "cdkintegrationtestuserpoolexplicitprops",
"UserPoolId": {
"Ref": "myuserpool01998219"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ const userpool = new UserPool(stack, 'myuserpool', {
userMigration: dummyTrigger('userMigration'),
verifyAuthChallengeResponse: dummyTrigger('verifyAuthChallengeResponse'),
},
snsRegion: Stack.of(stack).region,
});

const cognitoDomain = userpool.addDomain('myuserpooldomain', {
cognitoDomain: {
domainPrefix: 'myawesomeapp',
domainPrefix: 'cdkintegrationtestuserpoolexplicitprops',
},
});

Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-cognito/test/user-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,28 @@ describe('User Pool', () => {
});
});

test('snsRegion property is recognized', () => {
// GIVEN
const stack = new Stack();
const role = Role.fromRoleArn(stack, 'smsRole', 'arn:aws:iam::664773442901:role/sms-role');

// WHEN
new UserPool(stack, 'Pool', {
smsRole: role,
smsRoleExternalId: 'test-external-id',
snsRegion: 'test-region-1',
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Cognito::UserPool', {
SmsConfiguration: {
ExternalId: 'test-external-id',
SnsCallerArn: role.roleArn,
SnsRegion: 'test-region-1',
},
});
});

test('import using id', () => {
// GIVEN
const stack = new Stack(undefined, undefined, {
Expand Down

0 comments on commit 6eb775e

Please sign in to comment.