Implementing User Authentication with Amazon Cognito - Designing User Pools and Identity Pools

Learn about user authentication with Cognito User Pools, AWS resource access with Identity Pools, and social login integration.

Overview of Cognito

Cognito is a service that provides authentication, authorization, and user management for web and mobile applications, with the first 50,000 MAU (monthly active users) free. User Pools serve as user directories, managing sign-up, sign-in, and MFA. Identity Pools issue temporary AWS credentials to authenticated users, enabling direct access to AWS resources.

Choosing Between User Pools and Identity Pools

User Pools issue JWT tokens (ID tokens, access tokens, with configurable expiration from 5 minutes to 1 day) that are validated by API Gateway authorizers. Identity Pools receive User Pool tokens and return temporary AWS credentials based on IAM roles. When uploading files to S3 from the frontend, you call the S3 SDK directly using credentials obtained from the Identity Pool. Lambda triggers enable implementing email domain restrictions in Pre Sign-up, sending welcome emails in Post Confirmation, and adding custom claims in Pre Token Generation.

Advanced Authentication Features

Cognito's advanced security features provide adaptive authentication, dynamically determining MFA requirements based on risk level (device, IP address, login history). Logins from familiar devices skip MFA, while access from unknown devices or unusual IPs enforces MFA. Custom authentication flows using Lambda triggers enable implementing CAPTCHA verification and custom MFA. The User Pool hosted UI provides a customizable login page where you can apply your own branding. Token customization allows adding custom claims to ID tokens for use in application-side authorization decisions. To deepen your understanding of Cognito, specialized books on Amazon can also be helpful.

Cognito Pricing

Cognito pricing is based on monthly active users (MAU). The first 10,000 MAU are free, and up to 50,000 MAU costs approximately $0.0055 per MAU. SAML/OIDC federation users cost approximately $0.015 per MAU. Advanced security features (adaptive authentication, compromised credential detection) incur additional charges of approximately $0.050 per MAU. Identity Pool AWS credential issuance is free. With MAU-based billing, registered users who do not log in do not affect costs.

Summary

Cognito is a service that provides user authentication through User Pools and AWS resource access through Identity Pools. It integrates with external IdPs through social login and SAML/OIDC federation, and dynamically applies risk-based MFA through adaptive authentication. With the first 10,000 MAU free, it scales from startups to large-scale applications.