createUserPool

This action might generate an SMS text message. Starting June 1, 2021, US telecom carriers require you to register an origination phone number before you can send SMS messages to US phone numbers. If you use SMS text messages in Amazon Cognito, you must register a phone number with Amazon Pinpoint. Amazon Cognito uses the registered number automatically. Otherwise, Amazon Cognito users who must receive SMS messages might not be able to sign up, activate their accounts, or sign in.

If you have never used SMS text messages with Amazon Cognito or any other Amazon Web Service, Amazon Simple Notification Service might place your account in the SMS sandbox. In sandbox mode, you can send messages only to verified phone numbers. After you test your app while in the sandbox environment, you can move out of the sandbox and into production. For more information, see SMS message settings for Amazon Cognito user pools in the Amazon Cognito Developer Guide.

Creates a new Amazon Cognito user pool and sets the password policy for the pool.

If you don't provide a value for an attribute, Amazon Cognito sets it to its default value.

Amazon Cognito evaluates Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you must use IAM credentials to authorize requests, and you must grant yourself the corresponding IAM permission in a policy.

Learn more

Samples

import aws.sdk.kotlin.services.cognitoidentityprovider.model.AliasAttributeType
import aws.sdk.kotlin.services.cognitoidentityprovider.model.RecoveryOptionType
import aws.sdk.kotlin.services.cognitoidentityprovider.model.SchemaAttributeType
import aws.sdk.kotlin.services.cognitoidentityprovider.model.VerifiedAttributeType
fun main() { 
   //sampleStart 
   // The following example creates a user pool with all configurable properties set to an example value.
// The resulting user pool allows sign in with username or email address, has optional MFA, and has a
// Lambda function assigned to each possible trigger.
val resp = cognitoIdentityProviderClient.createUserPool {
    accountRecoverySetting = AccountRecoverySettingType {
        recoveryMechanisms = listOf<RecoveryOptionType>(
            RecoveryOptionType {
                name = RecoveryOptionNameType.fromValue("verified_email")
                priority = 1
            }                
        )
    }
    adminCreateUserConfig = AdminCreateUserConfigType {
        allowAdminCreateUserOnly = false
        inviteMessageTemplate = MessageTemplateType {
            emailMessage = "Your username is {username} and temporary password is {####}."
            emailSubject = "Your sign-in information"
            smsMessage = "Your username is {username} and temporary password is {####}."
        }
    }
    aliasAttributes = listOf<AliasAttributeType>(
        AliasAttributeType.fromValue("email")
    )
    autoVerifiedAttributes = listOf<VerifiedAttributeType>(
        VerifiedAttributeType.fromValue("email")
    )
    deviceConfiguration = DeviceConfigurationType {
        challengeRequiredOnNewDevice = true
        deviceOnlyRememberedOnUserPrompt = true
    }
    deletionProtection = DeletionProtectionType.fromValue("ACTIVE")
    emailConfiguration = EmailConfigurationType {
        configurationSet = "my-test-ses-configuration-set"
        emailSendingAccount = EmailSendingAccountType.fromValue("DEVELOPER")
        from = "support@example.com"
        replyToEmailAddress = "support@example.com"
        sourceArn = "arn:aws:ses:us-east-1:123456789012:identity/support@example.com"
    }
    emailVerificationMessage = "Your verification code is {####}."
    emailVerificationSubject = "Verify your email address"
    lambdaConfig = LambdaConfigType {
        kmsKeyId = "arn:aws:kms:us-east-1:123456789012:key/a6c4f8e2-0c45-47db-925f-87854bc9e357"
        customEmailSender = CustomEmailLambdaVersionConfigType {
            lambdaArn = "arn:aws:lambda:us-east-1:123456789012:function:MyFunction"
            lambdaVersion = CustomEmailSenderLambdaVersionType.fromValue("V1_0")
        }
        customSmsSender = CustomSmsLambdaVersionConfigType {
            lambdaArn = "arn:aws:lambda:us-east-1:123456789012:function:MyFunction"
            lambdaVersion = CustomSmsSenderLambdaVersionType.fromValue("V1_0")
        }
        customMessage = "arn:aws:lambda:us-east-1:123456789012:function:MyFunction"
        defineAuthChallenge = "arn:aws:lambda:us-east-1:123456789012:function:MyFunction"
        postAuthentication = "arn:aws:lambda:us-east-1:123456789012:function:MyFunction"
        postConfirmation = "arn:aws:lambda:us-east-1:123456789012:function:MyFunction"
        preAuthentication = "arn:aws:lambda:us-east-1:123456789012:function:MyFunction"
        preSignUp = "arn:aws:lambda:us-east-1:123456789012:function:MyFunction"
        preTokenGeneration = "arn:aws:lambda:us-east-1:123456789012:function:MyFunction"
        userMigration = "arn:aws:lambda:us-east-1:123456789012:function:MyFunction"
        verifyAuthChallengeResponse = "arn:aws:lambda:us-east-1:123456789012:function:MyFunction"
    }
    mfaConfiguration = UserPoolMfaType.fromValue("OPTIONAL")
    policies = UserPoolPolicyType {
        passwordPolicy = PasswordPolicyType {
            minimumLength = 6
            requireLowercase = true
            requireNumbers = true
            requireSymbols = true
            requireUppercase = true
            temporaryPasswordValidityDays = 7
        }
    }
    poolName = "my-test-user-pool"
    schema = listOf<SchemaAttributeType>(
        SchemaAttributeType {
            attributeDataType = AttributeDataType.fromValue("Number")
            developerOnlyAttribute = true
            mutable = true
            name = "mydev"
            numberAttributeConstraints = NumberAttributeConstraintsType {
                maxValue = "99"
                minValue = "1"
            }
            required = false
            stringAttributeConstraints = StringAttributeConstraintsType {
                maxLength = "99"
                minLength = "1"
            }
        }            
    )
    smsAuthenticationMessage = "Your verification code is {####}."
    smsConfiguration = SmsConfigurationType {
        externalId = "my-role-external-id"
        snsCallerArn = "arn:aws:iam::123456789012:role/service-role/test-cognito-SMS-Role"
    }
    smsVerificationMessage = "Your verification code is {####}."
    userAttributeUpdateSettings = UserAttributeUpdateSettingsType {
        attributesRequireVerificationBeforeUpdate = listOf<VerifiedAttributeType>(
            VerifiedAttributeType.fromValue("email")
        )
    }
    usernameConfiguration = UsernameConfigurationType {
        caseSensitive = true
    }
    userPoolAddOns = UserPoolAddOnsType {
        advancedSecurityMode = AdvancedSecurityModeType.fromValue("OFF")
    }
    userPoolTags = mapOf<String, String>(
        "my-test-tag-key" to "my-test-tag-key"
    )
    verificationMessageTemplate = VerificationMessageTemplateType {
        defaultEmailOption = DefaultEmailOptionType.fromValue("CONFIRM_WITH_CODE")
        emailMessage = "Your confirmation code is {####}"
        emailMessageByLink = "Choose this link to {##verify your email##}"
        emailSubject = "Here is your confirmation code"
        emailSubjectByLink = "Here is your confirmation link"
        smsMessage = "Your confirmation code is {####}"
    }
} 
   //sampleEnd
}