Overview
A serverless inference API that labels text as POSITIVE or NEGATIVE with DistilBERT. It runs as a Docker container on AWS Lambda behind API Gateway, and the repository covers the whole path from a model checkpoint to a public cloud endpoint.
Architecture
API Gateway receives the HTTP request and invokes the Lambda function, which runs a Docker container holding a FastAPI application. Mangum adapts FastAPI’s ASGI interface to Lambda’s event-based invocation. The DistilBERT model, fine-tuned on SST-2, is downloaded at image build time so a cold start does not have to fetch it.
Key Design Decisions
- Model baking. The model weights, about 260 MB, are downloaded and cached during
docker build, so Lambda never pays that download on a cold start. - ASGI adaptation. Mangum sits between FastAPI and Lambda, so the same code runs locally under Uvicorn and in the cloud without changes.
- Infrastructure as code. One AWS SAM template defines the Lambda function, the API Gateway, and the IAM roles.
Tech Stack
- ML Model: DistilBERT (Hugging Face Transformers)
- API Framework: FastAPI
- Lambda Adapter: Mangum
- Infrastructure: AWS SAM, API Gateway, Lambda
- Containerization: Docker (AWS Lambda Python base)