This guide provides a complete, step-by-step walkthrough for migrating and deploying the EDULearnning project to AWS using EC2, RDS, and Docker.
User → Internet → EC2 (Frontend/Backend) → AWS RDS (PostgreSQL)
- EC2 Instance: Hosts our Docker containers (Frontend & Backend).
- AWS RDS: Managed PostgreSQL database for persistent storage.
- Docker Compose: Manages multi-container orchestration on EC2.
- Frontend: HTML5, CSS3, JS (Served via Nginx)
- Backend: Python Flask + SQLAlchemy
- Database: AWS RDS (PostgreSQL)
- Containerization: Docker & Docker Compose
- Cloud Provider: AWS (Free Tier Eligible)
-
Create IAM User:
- Go to IAM Console → Users → Create User (
edulearn-admin). - Attach Policy:
AdministratorAccess. - Create Access Key and download the
.csvfile.
- Go to IAM Console → Users → Create User (
-
Configure AWS CLI on Local Machine:
aws configure # AWS Access Key ID: [Your Access Key] # AWS Secret Access Key: [Your Secret Key] # Default region name: us-east-1 # Default output format: json
-
Launch EC2:
- AMI: Amazon Linux 2023 (Free Tier).
- Instance Type: t2.micro or t3.micro.
- Key Pair: Create/Select
edulearn-key.pem. - Security Group:
- Port 22 (SSH) - Your IP
- Port 80 (HTTP) - 0.0.0.0/0
- Port 5000 (API) - 0.0.0.0/0
-
Connect to EC2:
chmod 400 edulearn-key.pem ssh -i "edulearn-key.pem" ec2-user@<EC2_PUBLIC_IP>
-
Install Docker & Docker Compose on EC2:
# Update System sudo yum update -y # Install Docker sudo yum install -y docker sudo service docker start sudo usermod -aG docker ec2-user # Install Docker Compose sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose # Verify Installations docker --version docker-compose --version # Re-login to apply group changes exit ssh -i "edulearn-key.pem" ec2-user@<EC2_PUBLIC_IP>
- Create RDS Instance:
- Engine: PostgreSQL (Standard Create).
- Tier: Free Tier.
- DB Instance ID:
edulearn-db. - Master Username:
dbadmin. - Master Password:
SecurePassword123.
- Security Group Configuration:
- In RDS Security Group, add Inbound Rule:
- Type:
PostgreSQL(Port 5432) - Source:
Custom→ Select your EC2 Security Group.
- Type:
- In RDS Security Group, add Inbound Rule:
-
Clone the Project:
git clone <YOUR_REPOSITORY_URL> cd EDULearnning
-
Set Environment Variables:
# Replace <RDS_ENDPOINT> with your actual RDS Endpoint from AWS Console export DATABASE_URL="postgresql://dbadmin:SecurePassword123@<RDS_ENDPOINT>:5432/edulearn" export JWT_SECRET_KEY="super-secret-key"
-
Run with Docker Compose:
# Build and Start Containers in detached mode docker-compose up -d --build -
Verify Running Containers:
docker ps
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/auth/signup |
Register a new user |
POST |
/api/auth/login |
Login and get JWT Token |
GET |
/api/courses/ |
List all courses |
POST |
/api/courses/ |
Create a course (Instructor) |
POST |
/api/courses/<id>/enroll |
Enroll in a course |
POST |
/api/courses/<id>/review |
Rate and Review a course |
If you prefer using AWS EKS instead of Docker Compose:
-
Create Cluster:
eksctl create cluster --name edulearn-cluster --region us-east-1 --nodegroup-name standard-nodes --node-type t3.micro --nodes 2 --managed
-
Create Secrets:
kubectl create secret generic edulearn-secrets \ --from-literal=database-url="postgresql://dbadmin:SecurePassword123@<RDS_ENDPOINT>:5432/edulearn" \ --from-literal=jwt-secret="super-secret-key"
-
Deploy Manifests:
kubectl apply -f k8s-backend.yaml kubectl apply -f k8s-frontend.yaml
-
Get LoadBalancer URL:
kubectl get service edulearn-frontend
To automate your deployments, create .github/workflows/deploy.yml:
- Build & Push: Automatically build Docker images and push to Docker Hub on every commit.
- Deploy: SSH into EC2 and run
docker-compose pull && docker-compose up -d.
When you are finished testing, delete these resources to stay within Free Tier:
- EC2: Terminate the instance.
- RDS: Delete the database (deselect "Create final snapshot").
- IAM: Delete the access keys.
- Cannot connect to DB: Ensure RDS Security Group allows port 5432 from EC2.
- Frontend can't find API: Check if EC2 Security Group allows port 5000.
- Permission Denied: Ensure you ran
sudo usermod -aG docker ec2-userand re-logged in.