Skip to content

End-to-end deployment project using FastAPI, Docker, and AWS EC2 — serves a machine learning insurance prediction API with a Streamlit frontend. Focuses on backend API dev, containerization, and cloud deployment.

Notifications You must be signed in to change notification settings

AbhaySingh71/Risk-Analytics-for-Insurance-with-Docker-and-Fastapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Risk Analytics for Insurance — FastAPI, Docker & AWS Deployment

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

📌 Project Objective

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.

🧱 Tech Stack

LayerTool/TechPurpose
🧠 ModelsklearnPredict insurance premium category
⚙️ BackendFastAPIRESTful API creation
📦 ContainerDockerPackaging application
☁️ CloudAWS EC2Hosting FastAPI + Docker
🌐 FrontendStreamlitSimple interactive UI

🗂️ Project Structure


├── 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

🚀 How to Run This Project

1️⃣ Clone the Repository

git clone https://github.com/AbhaySingh71/Risk-Analytics-for-Insurance-with-Docker-and-Fastapi.git
cd Risk-Analytics-for-Insurance-with-Docker-and-Fastapi

2️⃣ Create Virtual Environment (Optional)

python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt

3️⃣ Run FastAPI App

uvicorn app:app --reload

4️⃣ Launch Streamlit Frontend (Optional)

streamlit run frontend.py

5️⃣ Dockerize and Run

docker build -t insurance-api .
docker run -d -p 8000:8000 insurance-api

☁️ AWS EC2 Deployment Instructions

  1. Create an EC2 instance (Ubuntu)
  2. Connect to EC2 instance:
    ssh ubuntu@your-ec2-ip
  3. 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
  4. Reconnect to EC2 instance:
    ssh ubuntu@your-ec2-ip
  5. Run Docker container:
    docker pull abhaysingh71/fastapi-insurance-premium-prediction:latest
    docker run -p 8000:8000 abhaysingh71/fastapi-insurance-premium-prediction
  6. Update Security Group: Open port 8000 in EC2 security group settings
  7. Test the API:
    Visit: http://your-ec2-ip:8000/docs
  8. Update frontend: In frontend.py, change:
    API_URL = "http://your-ec2-ip:8000/predict"

🧪 API Docs

📸 Streamlit Preview

streamlit run frontend.py

🛠️ Features

  • ✅ Clean FastAPI backend
  • ✅ Docker containerized setup
  • ✅ AWS EC2 deployable
  • ✅ Simple Streamlit UI
  • ✅ Organized code structure

📢 Disclaimer

This project is not focused on ML model training.
It demonstrates API development, Dockerization, and cloud deployment.

👨‍💻 Author

About

End-to-end deployment project using FastAPI, Docker, and AWS EC2 — serves a machine learning insurance prediction API with a Streamlit frontend. Focuses on backend API dev, containerization, and cloud deployment.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published