Apps Development, AWS, Cloud Computing

4 Mins Read

A Guide to Register a User in Amazon Cognito using Python – Part 1

Voiced by Amazon Polly

Overview

In this multi-part series, we’ll explore the power of AWS Cognito and Boto3 in Python. Discover how to harness the capabilities of AWS Cognito to manage user registration more efficiently. In this first part, we’ll focus on registering users with AWS Cognito, providing you with a step-by-step guide to get started. Stay tuned for a comprehensive journey through AWS Cognito’s capabilities using the Boto3 client for Python. 

Pioneers in Cloud Consulting & Migration Services

  • Reduced infrastructural costs
  • Accelerated application deployment
Get Started

Objective

Demonstrate how to implement user authentication in Amazon Cognito using Python for secure and seamless access control in your applications.

Introduction

Amazon Cognito is a service that Amazon Web Services (AWS) provides identity and user management for your applications.

It’s commonly used to add user registration, authentication, and authorization features to web and mobile apps. AWS Cognito simplifies handling user identities and securing access to your application’s resources.

Key features and components of Amazon Cognito

  • User Pools: Create and manage user accounts with customizable authentication options.
  • Identity Pools (Federated Identities): Securely access AWS resources with temporary credentials.
  • Hosted UI: Pre-built, customizable web interface for user authentication.
  • Security Features: Multi-factor authentication, email/SMS verification, and adaptive authentication.
  • Social Identity Providers: Integration with popular social login providers.
  • Customization and Extensibility: Customize authentication flows and user attributes with Lambda triggers.
  • User Management: Manage user lifecycles, including registration and account recovery.
  • Sync and Analytics: Synchronize user data and track user activity across devices for analytics.

Amazon Cognito User Pool

An Amazon Cognito User Pool is a special way to check if someone should be allowed into an app. Think of it as a list of all the app’s users. Here’s how it works:

  • You can log in with your social media accounts or other services.
  • It can also help prove who you are to other apps.
  • If you use it, Amazon Cognito keeps track of your login info. Otherwise, other services do.

The app can use the list of users to know more about you. Amazon Cognito User Pool can do things like:

  • Let you sign up and log in.
  • Give you a website where you can sign up.
  • Let you log in with social media.
  • Keep a list of users and their info.
  • Use extra security like Multi-Factor Authentication (MFA).

Once you log in, the app gets a special code (JWT) that helps it trust you. This code gives you access to different parts of the app.

Step-by-Step Guide

Step 1: Sign-Up using Amazon Cognito, Python SDK Boto3

There are certain prerequisites for this code to work.

  • When you create the User Pool, choose the Sign-in option as shown below:

step1

  • When I made the user pool, I added a ‘preferred_username’ field so users can choose their username instead of using their email address as their username. Add “custom:” before the attribute name if you want to use custom attributes.

Required fields: preffered_username, email.

Custom Attributes: first_name, last_name.

  • Create a file called .env in the current directory where you have the below code. In this file, you should provide the macro COGNITO_USER_CLIENT_ID and COGNITO_REGION_NAME, with the client ID from Amazon Cognito > User Pool > (Your-user-pool-name) > App integration > Select your App Client.

step1b

  • When you execute the above code, you will get this back as a response

step1c

  • Now, if you check the Amazon Cognito > User Pools > (Your-user-pool-name) > Users, the user will be unconfirmed. You will see this and get a verification code in your email.

step1d

Step 2: Confirmation User using Amazon Cognito, Python SDK Boto3

  • You’re not a confirmed user but received a confirmation code in your email. Let’s figure out how to make you a confirmed user. Here’s the code to do it.

step2

  • When you execute the above code, you will get this back as a response

step2b

  • If you again go and check in Amazon Cognito > User Pools > (Your-user-pool-name) > Users, the user should be confirmed now.

step2c

Congratulations! You’ve successfully created your first app user.

Conclusion

We developed a registration component that enables users to sign up using the Amazon Cognito service with boto3. Amazon Cognito can be used for various common scenarios, including accessing AWS AppSync resources, verifying identity with third-party services, accessing AWS services through an identity pool, using AWS API Gateway and AWS Lambda user pools to access resources, and much more.

Drop a query if you have any questions regarding Amazon Cognito User Pool and we will get back to you quickly.

Making IT Networks Enterprise-ready – Cloud Management Services

  • Accelerated cloud migration
  • End-to-end view of the cloud environment
Get Started

About CloudThat

CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.

CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 850k+ professionals in 600+ cloud certifications and completed 500+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training PartnerAWS Migration PartnerAWS Data and Analytics PartnerAWS DevOps Competency PartnerAWS GenAI Competency PartnerAmazon QuickSight Service Delivery PartnerAmazon EKS Service Delivery Partner AWS Microsoft Workload PartnersAmazon EC2 Service Delivery PartnerAmazon ECS Service Delivery PartnerAWS Glue Service Delivery PartnerAmazon Redshift Service Delivery PartnerAWS Control Tower Service Delivery PartnerAWS WAF Service Delivery PartnerAmazon CloudFront Service Delivery PartnerAmazon OpenSearch Service Delivery PartnerAWS DMS Service Delivery PartnerAWS Systems Manager Service Delivery PartnerAmazon RDS Service Delivery PartnerAWS CloudFormation Service Delivery PartnerAWS ConfigAmazon EMR and many more.

FAQs

1. What is an Amazon Cognito User Pool?

ANS: – Amazon Cognito User Pool is a service for managing user identities and authentication in your applications.

2. How can I customize the sign-up process in Amazon Cognito User Pools?

ANS: – You can customize the sign-up process using AWS Lambda triggers to add custom validation and actions during registration.

3. What security features do Amazon Cognito User Pools offer?

ANS: – Amazon Cognito User Pools provide features like multi-factor authentication (MFA), email/SMS verification, and adaptive authentication for enhanced security.

WRITTEN BY Aritra Das

Aritra Das works as a Research Associate at CloudThat. He is highly skilled in the backend and has good practical knowledge of various skills like Python, Java, Azure Services, and AWS Services. Aritra is trying to improve his technical skills and his passion for learning more about his existing skills and is also passionate about AI and Machine Learning. Aritra is very interested in sharing his knowledge with others to improve their skills.

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!