Introduction

Amazon Cognito is a managed identity service that adds sign-up, sign-in, and access control to web and mobile applications. Authentication is the process of confirming who a user is. Authorization is the process of deciding what that user is permitted to do. This guide explains what Cognito is, the problem it was created to solve, how it operates, and the situations in which it is appropriate.

What is it?

Cognito is composed of two main parts. A user pool is a user directory that manages registration and sign-in and issues tokens that prove a user has signed in. A token is a signed piece of data that represents a fact, such as a completed sign-in. An identity pool, also called a federated identity pool, exchanges a proven identity for temporary AWS credentials so that an application can access AWS services directly. The two parts are often used together, and each can also be used on its own.

Why does it exist?

Building authentication correctly is difficult and carries significant risk. Passwords must be stored securely, tokens must be issued and validated, multi-factor authentication must be supported, and sign-in through external providers must be handled. Mistakes in any of these areas can expose user accounts. Cognito was created so that these responsibilities are handled by a managed service that follows established security standards, which removes the need for each application to build authentication from the beginning.

How it works

A user registers and signs in to a user pool, either through a hosted sign-in page that Cognito provides or through the application using a software development kit. When sign-in succeeds, the user pool issues three tokens. The ID token describes the user, the access token grants access to protected resources, and the refresh token is used to obtain new tokens without signing in again. The ID and access tokens are JSON Web Tokens, a standard format that is covered in the guide on JWT tokens.

If direct access to AWS services is required, the proven identity is passed to an identity pool, which returns temporary AWS credentials that are limited by a permission policy. Sign-in can also be delegated to an external identity provider, which is a service that authenticates users, a process known as federation.

Architecture diagram

User | v Cognito user pool --> issues ID, access, and refresh tokens | (JSON Web Tokens) | | | v | Access token is sent to | an API (via API Gateway) v Cognito identity pool --> exchanges the identity for temporary AWS credentials

Advantages

Disadvantages

Common use cases

Best practices

Common mistakes

Further reading in this library

Frequently Asked Questions

What is the difference between a user pool and an identity pool?
A user pool manages sign-up and sign-in and issues tokens that prove who a user is. An identity pool exchanges a proven identity for temporary AWS credentials so that the application can access AWS services directly.
What tokens does Cognito issue?
A user pool issues an ID token that describes the user, an access token that grants access to protected resources, and a refresh token used to obtain new tokens without signing in again. The ID and access tokens are JSON Web Tokens.
Does Cognito support multi-factor authentication?
Yes. A second proof of identity can be required through a one-time code sent by text message or generated by an authenticator application.
Can users sign in with Google or another provider?
Yes. Cognito supports federation, which allows sign-in through an external provider such as Google, Apple, or a corporate provider that uses SAML or OpenID Connect.
Is Amazon Cognito free?
Cognito provides a free tier for a number of monthly active users, after which charges apply based on the number of active users and on some advanced features.
AWS Cognito book cover
Go deeper ยท Book as a Service™
AWS Cognito

This article is the summary. The book is the full, continuously updated reference: user pools, identity pools, Lambda triggers, tokens, federation, and real-world website integration.

View the book