Mangum

0.21.0 · active · verified Thu Apr 09

Mangum is an adapter designed to run ASGI (Asynchronous Server Gateway Interface) applications, such as FastAPI, Starlette, Quart, and Django, within AWS Lambda environments. It handles various AWS event types including Function URLs, API Gateway (HTTP and REST APIs), Application Load Balancer, and CloudFront Lambda@Edge. The library is actively maintained, with frequent releases, and is currently at version 0.21.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to wrap a simple FastAPI application with Mangum to make it deployable as an AWS Lambda function. The `handler` object is the entry point for AWS Lambda, which Mangum uses to convert Lambda events into ASGI requests for your application.

from fastapi import FastAPI
from mangum import Mangum

app = FastAPI()

@app.get("/hello")
async def read_root():
    return {"message": "Hello from FastAPI on Lambda!"}

handler = Mangum(app)

# To test locally, you would typically run with uvicorn:
# uvicorn main:app --reload --port 8000
# For Lambda, `handler` is the entry point defined in your function configuration.

view raw JSON →