class UserPool (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.Cognito.UserPool |
Java | software.amazon.awscdk.services.cognito.UserPool |
Python | aws_cdk.aws_cognito.UserPool |
TypeScript (source) | @aws-cdk/aws-cognito » UserPool |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
, IUser
Define a Cognito User Pool.
Example
const pool = new cognito.UserPool(this, 'Pool');
pool.addClient('app-client', {
oAuth: {
flows: {
authorizationCodeGrant: true,
},
scopes: [ cognito.OAuthScope.OPENID ],
callbackUrls: [ 'https://my-app-domain.com/welcome' ],
logoutUrls: [ 'https://my-app-domain.com/signin' ],
},
});
Initializer
new UserPool(scope: Construct, id: string, props?: UserPoolProps)
Parameters
- scope
Construct
- id
string
- props
User
Pool Props
Construct Props
Name | Type | Description |
---|---|---|
account | Account | How will a user be able to recover their account? |
auto | Auto | Attributes which Cognito will look to verify automatically upon user sign up. |
custom | { [string]: ICustom } | Define a set of custom attributes that can be configured for each user in the user pool. |
custom | IKey | This key will be used to encrypt temporary passwords and authorization codes that Amazon Cognito generates. |
device | Device | Device tracking settings. |
email? | User | Email settings for a user pool. |
email | Email | Email settings for a user pool. |
enable | boolean | Setting this would explicitly enable or disable SMS role creation. |
lambda | User | Lambda functions to use for supported Cognito triggers. |
mfa? | Mfa | Configure whether users of this user pool can or are required use MFA to sign in. |
mfa | string | The SMS message template sent during MFA verification. |
mfa | Mfa | Configure the MFA types that users can use in this user pool. |
password | Password | Password policy for this user pool. |
removal | Removal | Policy to apply when the user pool is removed from the stack. |
self | boolean | Whether self sign up should be enabled. |
sign | Sign | Methods in which a user registers or signs in to a user pool. |
sign | boolean | Whether sign-in aliases should be evaluated with case sensitivity. |
sms | IRole | The IAM role that Cognito will assume while sending SMS messages. |
sms | string | The 'ExternalId' that Cognito service must using when assuming the smsRole , if the role is restricted with an 'sts:ExternalId' conditional. |
sns | string | The region to integrate with SNS to send SMS messages. |
standard | Standard | The set of attributes that are required for every user in the user pool. |
user | User | Configuration around admins signing up users into a user pool. |
user | string | Name of the user pool. |
user | User | Configuration around users signing themselves up to the user pool. |
accountRecovery?
Type:
Account
(optional, default: AccountRecovery.PHONE_WITHOUT_MFA_AND_EMAIL)
How will a user be able to recover their account?
autoVerify?
Type:
Auto
(optional, default: If signInAlias
includes email and/or phone, they will be included in autoVerifiedAttributes
by default.
If absent, no attributes will be auto-verified.)
Attributes which Cognito will look to verify automatically upon user sign up.
EMAIL and PHONE are the only available options.
customAttributes?
Type:
{ [string]:
ICustom
}
(optional, default: No custom attributes.)
Define a set of custom attributes that can be configured for each user in the user pool.
customSenderKmsKey?
Type:
IKey
(optional, default: no key ID configured)
This key will be used to encrypt temporary passwords and authorization codes that Amazon Cognito generates.
deviceTracking?
Type:
Device
(optional, default: see defaults on each property of DeviceTracking.)
Device tracking settings.
email?
Type:
User
(optional, default: cognito will use the default email configuration)
Email settings for a user pool.
emailSettings?
⚠️ Deprecated: Use 'email' instead.
Type:
Email
(optional, default: see defaults on each property of EmailSettings.)
Email settings for a user pool.
enableSmsRole?
Type:
boolean
(optional, default: CDK will determine based on other properties of the user pool if an SMS role should be created or not.)
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.
lambdaTriggers?
Type:
User
(optional, default: No Lambda triggers.)
Lambda functions to use for supported Cognito triggers.
mfa?
Type:
Mfa
(optional, default: Mfa.OFF)
Configure whether users of this user pool can or are required use MFA to sign in.
mfaMessage?
Type:
string
(optional, default: 'Your authentication code is {####}.')
The SMS message template sent during MFA verification.
Use '{####}' in the template where Cognito should insert the verification code.
mfaSecondFactor?
Type:
Mfa
(optional, default: { sms: true, otp: false }, if mfa
is set to OPTIONAL
or REQUIRED
.
{ sms: false, otp: false }, otherwise)
Configure the MFA types that users can use in this user pool.
Ignored if mfa
is set to OFF
.
passwordPolicy?
Type:
Password
(optional, default: see defaults on each property of PasswordPolicy.)
Password policy for this user pool.
removalPolicy?
Type:
Removal
(optional, default: RemovalPolicy.RETAIN)
Policy to apply when the user pool is removed from the stack.
selfSignUpEnabled?
Type:
boolean
(optional, default: false)
Whether self sign up should be enabled.
This can be further configured via the selfSignUp
property.
signInAliases?
Type:
Sign
(optional, default: { username: true })
Methods in which a user registers or signs in to a user pool.
Allows either username with aliases OR sign in with email, phone, or both.
Read the sections on usernames and aliases to learn more - https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html
To match with 'Option 1' in the above link, with a verified email, this property should be set to
{ username: true, email: true }
. To match with 'Option 2' in the above link with both a verified email and phone
number, this property should be set to { email: true, phone: true }
.
signInCaseSensitive?
Type:
boolean
(optional, default: true)
Whether sign-in aliases should be evaluated with case sensitivity.
For example, when this option is set to false, users will be able to sign in using either MyUsername
or myusername
.
smsRole?
Type:
IRole
(optional, default: a new IAM role is created)
The IAM role that Cognito will assume while sending SMS messages.
smsRoleExternalId?
Type:
string
(optional, default: No external id will be configured)
The 'ExternalId' that Cognito service must using when assuming the smsRole
, if the role is restricted with an 'sts:ExternalId' conditional.
Learn more about ExternalId here - https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user_externalid.html
This property will be ignored if smsRole
is not specified.
snsRegion?
Type:
string
(optional, 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)
The region to integrate with SNS to send SMS messages.
This property will do nothing if SMS configuration is not configured
standardAttributes?
Type:
Standard
(optional, default: All standard attributes are optional and mutable.)
The set of attributes that are required for every user in the user pool.
Read more on attributes here - https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html
userInvitation?
Type:
User
(optional, default: see defaults in UserInvitationConfig)
Configuration around admins signing up users into a user pool.
userPoolName?
Type:
string
(optional, default: automatically generated name by CloudFormation at deploy time)
Name of the user pool.
userVerification?
Type:
User
(optional, default: see defaults in UserVerificationConfig)
Configuration around users signing themselves up to the user pool.
Enable or disable self sign-up via the selfSignUpEnabled
property.
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
identity | IUser [] | Get all identity providers registered with this user pool. |
node | Construct | The construct tree node associated with this construct. |
stack | Stack | The stack in which this resource is defined. |
user | string | The ARN of the user pool. |
user | string | The physical ID of this user pool resource. |
user | string | User pool provider name. |
user | string | User pool provider URL. |
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
identityProviders
Type:
IUser
[]
Get all identity providers registered with this user pool.
node
Type:
Construct
The construct tree node associated with this construct.
stack
Type:
Stack
The stack in which this resource is defined.
userPoolArn
Type:
string
The ARN of the user pool.
userPoolId
Type:
string
The physical ID of this user pool resource.
userPoolProviderName
Type:
string
User pool provider name.
userPoolProviderUrl
Type:
string
User pool provider URL.
Methods
Name | Description |
---|---|
add | Add a new app client to this user pool. |
add | Associate a domain to this user pool. |
add | Add a new resource server to this user pool. |
add | Add a lambda trigger to a user pool operation. |
apply | Apply the given removal policy to this resource. |
grant(grantee, ...actions) | Adds an IAM policy statement associated with this user pool to an IAM principal's policy. |
register | Register an identity provider with this user pool. |
to | Returns a string representation of this construct. |
static from | Import an existing user pool based on its ARN. |
static from | Import an existing user pool based on its id. |
Client(id, options?)
addpublic addClient(id: string, options?: UserPoolClientOptions): UserPoolClient
Parameters
- id
string
- options
User
Pool Client Options
Returns
Add a new app client to this user pool.
Domain(id, options)
addpublic addDomain(id: string, options: UserPoolDomainOptions): UserPoolDomain
Parameters
- id
string
- options
User
Pool Domain Options
Returns
Associate a domain to this user pool.
ResourceServer(id, options)
addpublic addResourceServer(id: string, options: UserPoolResourceServerOptions): UserPoolResourceServer
Parameters
- id
string
- options
User
Pool Resource Server Options
Returns
Add a new resource server to this user pool.
Trigger(operation, fn)
addpublic addTrigger(operation: UserPoolOperation, fn: IFunction): void
Parameters
- operation
User
Pool Operation - fn
IFunction
Add a lambda trigger to a user pool operation.
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
grant(grantee, ...actions)
public grant(grantee: IGrantable, ...actions: string[]): Grant
Parameters
- grantee
IGrantable
- actions
string
Returns
Adds an IAM policy statement associated with this user pool to an IAM principal's policy.
IdentityProvider(provider)
registerpublic registerIdentityProvider(provider: IUserPoolIdentityProvider): void
Parameters
- provider
IUser
Pool Identity Provider
Register an identity provider with this user pool.
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
UserPoolArn(scope, id, userPoolArn)
static frompublic static fromUserPoolArn(scope: Construct, id: string, userPoolArn: string): IUserPool
Parameters
- scope
Construct
- id
string
- userPoolArn
string
Returns
Import an existing user pool based on its ARN.
UserPoolId(scope, id, userPoolId)
static frompublic static fromUserPoolId(scope: Construct, id: string, userPoolId: string): IUserPool
Parameters
- scope
Construct
- id
string
- userPoolId
string
Returns
Import an existing user pool based on its id.