Creating Cognito user pool with AWS CLI

In this section, we will create a user pool by using CLI commands:

  1. Generate the input JSON template, using the generate-cli-skeleton option:
aws cognito-idp create-user-pool 
--pool-name my-pool-from-cli
--generate-cli-skeleton

This command will return a template with all of the supported properties for the create-user-pool sub-command, in the correct JSON format. 

  1. Fill in the properties that are required within the JSON file, and remove the properties that are not required:
    1. Start the JSON file, specifying a name by using the PoolName property:
{
"PoolName": "MyFirstUserPool",
    1. Under the Policies section, we will define the password policy, using the PasswordPolicy sub-property:
"Policies": {
"PasswordPolicy": {
"MinimumLength": 8,
"RequireUppercase": true,
"RequireLowercase": true,
"RequireNumbers": true,
"RequireSymbols": true
}
},
    1. Define AutoVerifiedAttributes and AliasAttributes, as follows:
"AutoVerifiedAttributes": [
"email"
],
"AliasAttributes": [
"email"
],

Refer to the How it works... section for more details.

    1. Define an email verification message and an email verification subject:
"EmailVerificationMessage": "Your verification code from MyApp is {####}.",
"EmailVerificationSubject": "Your verification code from MyApp",
In this recipe, we will only demonstrate email verification. In a later recipe, we will look at how to do SMS verification.
    1. Define a tag by using the UserPoolTags property, as follows:
"UserPoolTags": {
"Team": "Dev"
},
    1. Define the AdminCreateUserConfig property, as follows:
"AdminCreateUserConfig": {
"AllowAdminCreateUserOnly": false,
"UnusedAccountValidityDays": 7,
"InviteMessageTemplate": {
"EmailMessage": "Your username for MyApp is {username} and password is {####}.",
"EmailSubject": "Your temporary password for MyApp"
}
}

The AllowAdminCreateOnly property, if set to true, restricts creating accounts to administrators. We will set it to false, as we will be doing user sign-up with this user pool in a later recipe. The complete JSON file is available in the code files.

  1. Execute the aws congnito-idp create-user-pool command, specifying this JSON file:
aws cognito-idp create-user-pool 
--cli-input-json file://resources/create-user-pool-cli-input.json
--profile admin

Note the user-pool-id, for use in future commands.

We can verify user-pool-created by using the describe-user-pool sub-command:

aws cognito-idp describe-user-pool 
--user-pool-id us-east-1_u0YJPtdpv
--profile admin

Remember to replace the user-pool-id value with our user-pool-id from the previous command. The describe-user-pool sub-command returns the current properties of the user-pool.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.17.12