Skip to main content

Secure FastAPI in the Cloud

A compact FastAPI reference app with a working Books API, rich request logging, and balanced guidance for authentication and deployment on AWS, GCP, and Azure.

6

Books Endpoints

3

Cloud Providers

0

Secrets in Code

FastAPIAWSGCPAzure
main.py
from fastapi import FastAPI, Query
from pydantic import BaseModel

class BookListResponse(BaseModel):
  items: list[BookResponse]
  total: int
  skip: int
  limit: int

@app.get("/api/v1/books", response_model=BookListResponse)
async def list_books(skip: int = Query(0, ge=0), limit: int = Query(20, ge=1, le=100)):
  return paginate_books(list(store.values()), skip=skip, limit=limit)

What The Docs Cover

Concepts first, implementation second

Six core topics covered by the documentation. The live demo app implements the API-focused pieces and stays intentionally small.

JWT Bearer Auth

Stateless, self-contained tokens with short expiry. Verify cryptographically โ€” no DB round-trip per request. Powered by HS256 or RS256.

Cloud IAM / Workload Identity

Zero secrets in code. IRSA on AWS, Workload Identity on GCP, Managed Identity on Azure. Your app gets short-lived tokens automatically from the platform.

Enterprise SSO

Cognito (AWS), Google Identity (GCP), or Microsoft Entra ID โ€” enterprise login with MFA, conditional access, and app roles. JWKS-validated RS256 tokens.

RBAC Scopes

Fine-grained authorization with OAuth2 scopes. Use Security() โ€” not just Depends() โ€” to cleanly enforce access per endpoint.

Pydantic v2 Models

Separate request/response models so internal fields never leak. model_dump(exclude_unset=True) for clean partial updates.

Auto OpenAPI 3.1

Interactive Swagger UI and ReDoc generated from your type annotations โ€” no YAML to maintain. Security schemes auto-wired.

Quick Start

Up and running in 60 seconds

The live demo focuses on the Books API and observability basics. Hit /docs for the interactive Swagger UI. Auth and deployment patterns are explained in the docs alongside the running demo.

Full Setup Guide โ†’
zsh
$
git clone https://github.com/jaredthivener/python-demo# clone the repo
$
cd python-demo
$
uv sync --group dev# install dependencies
$
uvicorn main:app --reload --no-access-log# start the server

INFO: ย ย  Started server process
INFO: ย ย  Waiting for application startup.
INFO: ย ย  Application startup complete.
INFO: ย ย  Uvicorn running on http://127.0.0.1:8000