Skip to content
GitHubXDiscordRSS

UserPool

Learn how to create, update, and manage AWS Cognito UserPools using Alchemy Cloud Control.

The UserPool resource lets you manage AWS Cognito UserPools for user authentication and management in your applications.

Create a basic UserPool with required properties and some common optional settings.

import AWS from "alchemy/aws/control";
const userPool = await AWS.Cognito.UserPool("myUserPool", {
UserPoolName: "MyUserPool",
Policies: {
PasswordPolicy: {
MinimumLength: 8,
RequireUppercase: true,
RequireLowercase: true,
RequireNumbers: true,
RequireSymbols: true
}
},
UserPoolTags: {
Environment: "Development",
Purpose: "User Authentication"
}
});

Configure a UserPool with advanced settings, including multi-factor authentication (MFA) and email configurations.

const advancedUserPool = await AWS.Cognito.UserPool("advancedUserPool", {
UserPoolName: "AdvancedUserPool",
MfaConfiguration: "ON",
SmsConfiguration: {
SnsCallerArn: "arn:aws:iam::123456789012:role/SMSRole",
ExternalId: "MyExternalId"
},
EmailConfiguration: {
EmailSendingAccount: "DEVELOPER",
From: "no-reply@mydomain.com",
ReplyToEmailAddress: "support@mydomain.com",
SourceArn: "arn:aws:ses:us-west-2:123456789012:identity/mydomain.com"
},
UserPoolTags: {
Environment: "Production"
}
});

Add custom user attributes to the UserPool schema.

const customAttributeUserPool = await AWS.Cognito.UserPool("customAttrUserPool", {
UserPoolName: "CustomAttributeUserPool",
Schema: [
{
Name: "custom:favorite_color",
AttributeDataType: "String",
Mutable: true,
Required: false
},
{
Name: "custom:birthdate",
AttributeDataType: "String",
Mutable: true,
Required: false
}
],
UserPoolTags: {
Purpose: "User Management"
}
});

Set up a UserPool with configurations for user sign-up and account recovery.

const signUpConfigUserPool = await AWS.Cognito.UserPool("signUpConfigUserPool", {
UserPoolName: "SignUpConfigUserPool",
AdminCreateUserConfig: {
AllowAdminCreateUserOnly: false,
UnusedAccountValidityDays: 7
},
AccountRecoverySetting: {
RecoveryMechanisms: [
{
Name: "verified_email",
Priority: 1
},
{
Name: "verified_phone_number",
Priority: 2
}
]
},
UserPoolTags: {
Purpose: "User Authentication"
}
});