A full-stack API-first project that demonstrates how to build and deploy a FastAPI-based prediction service using Docker and AWS EC2. This project is not about ML model building, but focuses on the end-to-end deployment pipeline including:
- 🚀 FastAPI for high-performance backend API
- 🐳 Docker for containerization
- ☁️ AWS EC2 for production deployment
- 🌐 Streamlit frontend integration
- 🔁 Model integration to serve predictions as an API
To demonstrate an end-to-end deployment pipeline using FastAPI for API development, Docker for containerization, and AWS EC2 for hosting a cloud-based prediction service.
The ML model (predicting insurance premium category) is pre-trained and used only for demonstration purposes.
Layer | Tool/Tech | Purpose |
---|---|---|
🧠 Model | sklearn | Predict insurance premium category |
⚙️ Backend | FastAPI | RESTful API creation |
📦 Container | Docker | Packaging application |
☁️ Cloud | AWS EC2 | Hosting FastAPI + Docker |
🌐 Frontend | Streamlit | Simple interactive UI |
├── app.py # FastAPI application
├── frontend.py # Streamlit UI
├── model/ # Random Forest model + loading logic
│ └── model.pkl
├── config/ # Configs for API behavior
├── schema/ # Pydantic data validation schemas
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration for app
├── .dockerignore # Files to ignore in Docker build
└── README.md # This file
git clone https://github.com/AbhaySingh71/Risk-Analytics-for-Insurance-with-Docker-and-Fastapi.git
cd Risk-Analytics-for-Insurance-with-Docker-and-Fastapi
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn app:app --reload
streamlit run frontend.py
docker build -t insurance-api .
docker run -d -p 8000:8000 insurance-api
- Create an EC2 instance (Ubuntu)
- Connect to EC2 instance:
ssh ubuntu@your-ec2-ip
- Run the following setup commands:
sudo apt-get update sudo apt-get install -y docker.io sudo systemctl start docker sudo systemctl enable docker sudo usermod -aG docker $USER exit
- Reconnect to EC2 instance:
ssh ubuntu@your-ec2-ip
- Run Docker container:
docker pull abhaysingh71/fastapi-insurance-premium-prediction:latest docker run -p 8000:8000 abhaysingh71/fastapi-insurance-premium-prediction
- Update Security Group: Open port
8000
in EC2 security group settings - Test the API:
Visit:http://your-ec2-ip:8000/docs
- Update frontend: In
frontend.py
, change:API_URL = "http://your-ec2-ip:8000/predict"
streamlit run frontend.py
- ✅ Clean FastAPI backend
- ✅ Docker containerized setup
- ✅ AWS EC2 deployable
- ✅ Simple Streamlit UI
- ✅ Organized code structure
This project is not focused on ML model training.
It demonstrates API development, Dockerization, and cloud deployment.
- Abhay Singh
- Email: abhaysingh71711@gmail.com
- LinkedIn: Abhay's LinkedIn
- GitHub: AbhaySingh71