Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

FastAPI
  • FastAPI Hello World: Routes, uvicorn and the Free Swagger Page
  • RESTful API Basics: Resources, Methods, Stateless Requests and Status Codes
  • Django, FastAPI or Flask? The Same Blog Feature in Three Shapes, and How to Choose
  • One Blog, Three Frameworks: Routing, Models, Templates and Layout in Django, FastAPI and Flask
  • Backend vs Frontend: What Runs Where, and Why the Server Is the One You Trust
  • One Request, Two Answers: the Same Post as an HTML Page and as JSON
  • What FastAPI Is: Starlette, Pydantic, uvicorn and What async def Really Gives You
  • Building a Blog with an AI Coding Agent: Plan Mode, a Master Prompt and the First Review
  • Handing a Figma Design to an AI Agent: Compare the Files, Then Review the Change
  • Inside a FastAPI Blog: Every Folder and File an AI Agent Built, and What to Question
  • Swagger UI and OpenAPI in FastAPI: Reading the Contract Your Code Writes
  • POST, PUT and DELETE in FastAPI: Choosing 201, 200, 204 and 404 on the Server
  • Paging, Sorting and Filtering a REST API in FastAPI
  • File Upload and Download in FastAPI: multipart, UploadFile and FileResponse
  • API Versioning in FastAPI with an API-Version Header
  • Idempotent REST Methods, HATEOAS and the Maturity Model: Which Requests Are Safe to Repeat
  • A FastAPI REST API End to End: One App Visit, Seven Requests
  • The Book API in FastAPI: A Contract a React Client Can Rely On
  • A React Client for a FastAPI API: The CORS Wall, CORSMiddleware and the Vite Proxy
  • Dependency Injection With FastAPI Depends: Providers, dependency_overrides and yield
  • A Layered FastAPI Project: Controllers, Services, Schemas and One Folder per Concern
  • FastAPI Request and Response Models with Pydantic: Design the JSON on Purpose
  • FastAPI Path, Query and Body Parameters: Reading a 422, response_model and Depends
  • Validation and Problem Details in FastAPI: From a 422 to One Error Shape for the Whole API
  • FastAPI with SQLAlchemy Models and Alembic Migrations: A Table from a Class, a Session per Request
  • From a List to a Database in FastAPI: Route, Service, Repository and the SQL SQLAlchemy Sends
  • Docker Compose: Run a FastAPI App and Postgres From One File
  • Docker Health Checks, Networks and Resource Limits: Up Is Not Enough
  • Repository and Unit of Work With SQLAlchemy: Both Writes or Neither, and a Test With No Database
  • How a Request and a Login Flow Through a FastAPI Blog: Depends, bcrypt, a Signed Session Cookie and async def
  • An Auth Starter Kit with Keycloak: Build Sign In Once, Put the Backend Between React and the Identity Provider
  • Protecting a Python API with Keycloak: Check the JWT Signature, Issuer and Expiry in FastAPI, Django and Flask
  • How an Identity Provider Login Works: The OpenID Connect Code Flow vs a Backend Password Grant, with Keycloak
  • AWS Cognito vs Keycloak: User Pools, App Clients and When a Managed Identity Provider Wins
  • Migrating FastAPI from Keycloak to AWS Cognito: The Four Values, the JWKS Address and Every Check on an Access Token
  • Testing a Cognito Login End to End: Allow the Password Flow, Confirm the Email Code, and Reset a Forgotten Password
  • Enterprise Integration for an AI App: One Adapter per Edge for SSO, the CRM, a Legacy CSV and Webhooks
  • Testing a FastAPI Blog with pytest: a Test Database through dependency_overrides, Login Fixtures and Reading a Failure
  • Smoke-Testing a Dockerized LLM App by Hand: Stage the Weights, Check Every Layer, Make Errors Say Why
  1. Blog
  2. /
  3. FastAPI
  4. /
  5. Authentication

AWS Cognito vs Keycloak: User Pools, App Clients and When a Managed Identity Provider Wins

Cognito is AWS's identity service, Keycloak as a service. Its three pieces (user pool, app client, hosted UI), the tokens it issues, a side-by-side with Keycloak on running costs and lock-in, and why the rest of the subtitle app doesn't change when the door is swapped.

Chaand Sheikh

·27 November 2026·Updated 29 November 2026Authentication

What you will learn

  • Describe Cognito's user pool, app client and hosted UI, and map each to Keycloak
  • List the tokens and features Cognito gives you
  • Compare Keycloak and Cognito on who runs it, cost and where the users live
  • See why only one box changes when an app moves from Keycloak to Cognito

Before you start

  • How an identity provider login works

So far the subtitle app's identity provider has been Keycloak, running in Docker next to the backend. Now it moves to AWS Cognito. Before any code, here's what Cognito is and why it's the better fit for this app.

The migration itself was handed to a coding agent, the Codex app from OpenAI, set to auto-review permissions and high intelligence, with a plain-English prompt: scan the project (backend, front end, Keycloak as the identity provider), migrate everything to AWS Cognito including the controllers and business logic, and create a sample .env with the details you need. While it worked, this is what there was to learn.

What Cognito is

Cognito is the identity service of AWS. It handles sign up, sign in and the tokens your app checks, which is the same job Keycloak does. The difference is who runs it. With Keycloak you run the container, its database and its upgrades. With Cognito, AWS runs all of that. So you can think of Cognito as Keycloak as a service. It speaks the same standard protocols, OAuth 2 and OpenID Connect, and issues signed JWT tokens, just like Keycloak.

Three pieces

Cognito pieces and their Keycloak twins Cognito Keycloak User pool Realm App client (client ID) Client Hosted UI Keycloak login page the directory of users how one app talks to the pool ready sign in pages
Each Cognito piece has a twin in Keycloak, so the design stays the same.
  • User pool. The directory of your users, where they sign up, sign in and keep their passwords and details. Close to a Keycloak realm.
  • App client. How one application talks to the user pool, with its own client ID. The React front end uses one. In Keycloak, that's the client.
  • Hosted UI. A ready-made sign in and sign up page that Cognito serves on its own domain, like the Keycloak login page.

The user signs in on the hosted UI, Cognito checks them against the user pool, and sends the tokens back to the app.

What you get

  • An ID token that says who the user is, and an access token that your API checks. Both are signed JWTs. A refresh token gets new ones when they expire.
  • Multi-factor authentication built in.
  • Social login with Google, Facebook, Apple or Amazon in a few settings.
  • Single sign on with a company's identity provider through SAML or OpenID Connect.
  • Scaling and patching by AWS.

Side by side

KeycloakCognito
Who runs itYouAWS
ProtocolsOAuth 2, OpenID Connect, JWTOAuth 2, OpenID Connect, JWT
Social login and SSOYes, more for you to configure and maintainYes, a few settings
CostThe server it runs on, all the timeBy monthly active users, with a free tier
Where users liveWherever you host it, no vendor lock-inYour AWS account, in the region you choose; moving out later is harder

Microsoft Azure and Google Cloud have similar managed services. If your app runs on their cloud, they're worth a look.

Why switch?

Keycloak is excellent, but for a small team building an AI subtitle app, Cognito wins on three things. Zero operations: there's nothing to babysit. Social login in a few clicks. And it stays cheap as you grow. At a company where I worked as a machine learning engineer, we ran Keycloak, and the patches and upgrades kept coming back. Once we moved to Cognito, life got much easier. It's the best fit for apps already on AWS, and this app already keeps its videos in S3.

Here's the Keycloak work that simply goes away: no container to run and no database behind it, no realm file to import, no TLS certificates (every Cognito endpoint is already HTTPS), no patches, no scaling worries and no backups.

The cost model

Cognito charges by monthly active users. If a hundred people sign up but only ten use the app this month, you pay for those ten. While you develop and test, a small app stays inside the free tier. Prices change, so check the Cognito pricing page for current numbers. Even as a product grows, it's usually cheaper than running a server for Keycloak with its database and backups.

Only one box changes

In the subtitle app's architecture, the Keycloak box goes out and Cognito comes in. The React front end still sends the user to sign in, and FastAPI still checks the token on every call. The Celery worker, Redis, Whisper and S3 don't change at all. The code side of the move is in migrating to Cognito and verifying its tokens.

Quick recap

  • Cognito is the managed identity service of AWS: Keycloak as a service.
  • A user pool holds the users, an app client connects your app, the hosted UI gives sign in pages.
  • Same protocols and signed JWTs, so the design stays the same.
  • You trade running costs and upgrades for a per-active-user bill and users stored in your AWS account.

Keep going in FastAPI · 34 of 39

Previous
How an Identity Provider Login Works: The OpenID Connect Code Flow vs a Backend Password Grant, with Keycloak
Next post
Migrating FastAPI from Keycloak to AWS Cognito: The Four Values, the JWKS Address and Every Check on an Access Token
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Related posts

How a Request and a Login Flow Through a FastAPI Blog: Depends, bcrypt, a Signed Session Cookie and async def

Follow GET / through the FastAPI blog to two SQL statements and an HTML page, then a login: one SELECT, a bcrypt check, a 303 with a signed session cookie that decodes to user_id 1. A changed cookie gets 401, a plain user 403, and three slow requests on async def with a blocking session finish at 1.92 s while a ping waits 1.83 s.

An Auth Starter Kit with Keycloak: Build Sign In Once, Put the Backend Between React and the Identity Provider

Almost every project needs sign in, sign out and a token check, so build them once in a starter kit. Tour the kit's four pillars, then finish it: a fix prompt, a backend that sits between React and Keycloak with register, login, me and logout routes, and the limits of a stateless access token.

Protecting a Python API with Keycloak: Check the JWT Signature, Issuer and Expiry in FastAPI, Django and Flask

Keycloak signs the access token; your API only checks it. Run Keycloak in Docker with a realm file, fetch its public keys once, check RS256, the issuer and the expiry, and protect /api/me with one Depends. Then the same check as a Django REST framework class and a Flask decorator.

How an Identity Provider Login Works: The OpenID Connect Code Flow vs a Backend Password Grant, with Keycloak

What an identity provider does, the four Keycloak words you see everywhere, the standard OpenID Connect sign in (redirect, code, token), and the custom-page version where FastAPI sends a password grant. Then one token followed from login to the check, plus refresh, logout and dev mode.

On this page

  • What Cognito is
  • Three pieces
  • What you get
  • Side by side
  • Why switch?
  • The cost model
  • Only one box changes
  • Quick recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.