Making FastAPI Work with Zappa on AWS Lambda (Without Losing Your Mind)




Making FastAPI Work with Zappa on AWS Lambda (Without Losing Your Mind)

A few days ago, we explored how to use FastAPI with Magnum on AWS Lambda, wrapping the app in Mangum and deploying via API Gateway. That setup worked well—clean, fast, and serverless. But then came the next natural question:

Can I use Zappa to deploy my FastAPI app to Lambda?

The short answer: Yes, but it’s not always plug-and-play. Let’s walk through when Zappa makes sense, how to configure it for FastAPI, and why CLI-first deployment is your best bet moving forward.


Why Zappa?

Zappa’s been around for a while. It was built to make serverless easy for Flask and Django developers by handling AWS Lambda packaging and API Gateway wiring behind the scenes. It shines when you want fast, simple deployment without touching the AWS console.

But here’s the catch: Zappa is WSGI-first. FastAPI is ASGI-native. So you need a bridge—and that’s where Mangum comes in.


FastAPI + Zappa + Mangum: The Minimal Setup

Create a file called main.py

Python
from fastapi import FastAPI
from mangum import Mangum

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello from Zappa + FastAPI!"}

handler = Mangum(app)


Then add a zappa_settings.json file: 

JSON
{
  "dev": {
    "app_function": "main.handler",
    "aws_region": "us-east-1",
    "profile_name": "default",
    "project_name": "fastapi-zappa-demo",
    "runtime": "python3.9",
    "s3_bucket": "your-zappa-deployments"
  }
}   


Make sure to create and activate a virtual environment before installing: 

Bash
python3 -m venv venv
source venv/bin/activate
pip install fastapi mangum zappa uvicorn   


Then deploy with Zappa: 

Bash
zappa deploy dev  


Zappa will package your app, upload it to S3, and deploy it to Lambda behind an API Gateway.


CLI Tips to Inspect the Deployment

Forget screenshots—use the AWS CLI for everything:

Check deployed Lambda function:

Bash
aws lambda get-function --function-name fastapi-zappa-demo-dev  


Check the API Gateway endpoint: 

Bash
aws apigateway get-rest-apis | jq '.items[] | select(.name | contains("fastapi"))'


Tail logs if something breaks: zappa tail dev

Bash
zappa tail dev


And to clean up when you’re done:

Bash
zappa undeploy dev  


When Should You Use Zappa?

Zappa is still a useful tool in 2025—especially for Flask-style WSGI apps or smaller FastAPI experiments. It’s fast to set up and gets you a working URL in minutes. But for serious ASGI apps or long-term infrastructure, you might be better off with Serverless Framework, AWS CDK, or sticking with the Magnum + API Gateway combo you already got working.

The good news? You’re now comfortable in both worlds.

Need help tweaking your Zappa config or untangling CLI output? You’re not alone. Let’s keep building this CLI-first serverless stack together. ☕🚀


Downloads

Download the FastAPI + Zappa Starter Template (ZIP)

View the source files on GitHub Gist




Need AWS Expertise?

If you're looking for guidance on AWS or any cloud challenges, feel free to reach out! We'd love to help you tackle your projects. 🚀


Email us at: info@pacificw.com


Image: Gemini

Comments

Popular posts from this blog

The New ChatGPT Reason Feature: What It Is and Why You Should Use It

Raspberry Pi Connect vs. RealVNC: A Comprehensive Comparison

The Reasoning Chain in DeepSeek R1: A Glimpse into AI’s Thought Process