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(cognito): configure SNS region for UserPool SMS messages #19519

Merged
merged 3 commits into from Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-cognito/lib/user-pool.ts
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
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
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
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