Deploy your complete AI application stack to production: Next.js to Vercel and Flask MLOps service to AWS EC2.
Lab Overview
What You'll Do: Deploy Next.js to Vercel (production), deploy Flask MLOps container to AWS EC2, and connect everything for a live production system
Lab Collaborators:
- Edward Lampoh - Software Developer & Collaborator
- Oluwafemi Adebayo, PhD - Academic Professor & Collaborator
🚨 Prerequisites Required
You must complete Labs 1-6 with working Docker containers and Kubernetes knowledge before starting Lab 7.
Prerequisites Check
Before starting Lab 7, ensure you have:
- ✅ Docker image built:
docker images | grep mlops-service - ✅ Kubernetes deployment working from Lab 6
- ✅ Next.js app running locally
- ✅ AWS account created (from Lab 1)
- ✅ Credit/debit card for AWS (using free tier only)
📝 Important Note
This lab uses AWS free tier exclusively. Everything you'll do in this lab is covered under AWS free tier - you won't be charged as long as you use the resources specified in this lab (t2.micro instance, 8 GB storage).
Part A: Understanding Cloud Deployment
Learn what cloud deployment means and why it's essential
1. What is Cloud Deployment?
Cloud deployment means running your application on servers managed by cloud providers (AWS, Google Cloud, Azure) instead of your own computer.
2. Why Deploy to Cloud?
Cloud deployment benefits:
- • Available 24/7
- • Accessible from anywhere in the world
- • Automatic scaling based on demand
- • Professional monitoring and backups
3. Our Cloud Architecture
What We're Deploying:
Users (Internet)
↓
Next.js App (Vercel)
↓
Flask MLOps Service (AWS EC2)
↓
Neon PostgreSQL (Already Cloud-Based)4. AWS EC2 Basics
What is EC2? EC2 = Elastic Compute Cloud - a virtual computer running in AWS data centers.
Part B: Deploy Next.js to Vercel
Deploy your Next.js application to production hosting
1. What is Vercel?
Vercel is a platform built specifically for Next.js applications:
- • Created by the team that built Next.js
- • Automatic deployments from GitHub
- • Global CDN (fast anywhere in the world)
- • Free tier for hobby projects
- • SSL certificates included
2. Connect GitHub
Sign in to Vercel:
- Go to vercel.com
- Click "Sign Up" or "Login"
- Choose "Continue with GitHub"
- Authorize Vercel to access your repositories
3. Configure Environment Variables
Before deploying, add your environment variables in Vercel.
4. Deploy to Vercel
- Click "Deploy" button
- Wait 2-3 minutes for build to complete
- Click "Visit" to see your live site
5. Test Your Deployment
Visit your Vercel URL and test the application.
Part C: AWS Account & IAM Setup
Prepare your AWS account for EC2 deployment
1. Sign in to AWS Console
- Go to aws.amazon.com
- Click "Sign In to the Console"
- Enter your AWS account credentials (created in Lab 1)
2. Select Your Region
Choose a region close to you from the top-right dropdown.
3. Create EC2 Key Pair
Key pairs let you securely access your EC2 instance.
# Mac/Linux - Set permissions
chmod 400 ~/.ssh/mlops-service-key.pem4. Create Security Group
Security groups control network access to your EC2 instance.
Part D: Deploy Flask to AWS EC2
Launch an EC2 instance and run your Docker container
1. Launch EC2 Instance
- Go to EC2 Dashboard
- Click "Launch instance" button
2. Configure Instance Details
Instance type: Select t2.micro (free tier - required for this course)
4. Get Instance Public IP
Copy the public IP address from your instance details.
5. Connect to EC2
# Connect via SSH
ssh -i ~/.ssh/mlops-service-key.pem ubuntu@YOUR_EC2_PUBLIC_IP6. Install Docker on EC2
# Update and install Docker
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io7. Transfer Docker Image
Rebuild your Docker image on EC2 by cloning your repository.
8. Create Environment File
Create a .env file on EC2 with your production environment variables.
9. Run Docker Container
# Run container
docker run -d \
--name mlops-service \
--restart unless-stopped \
-p 5001:5001 \
--env-file .env \
mlops-service:latest10. Test Flask Service
# Test health endpoint
curl http://YOUR_EC2_PUBLIC_IP:5001/healthPart E: Connect Services
Link Vercel and AWS together for production system
1. Update Vercel Environment
- Go to Vercel project settings
- Update MLOPS_SERVICE_URL to your EC2 IP
- Redeploy
2. Test End-to-End
Test the complete flow from Vercel to AWS.
3. Configure CORS
Update CORS settings in Flask if needed.
Part F: Understanding AWS Free Tier
Learn about AWS free tier and how to track your usage
1. Understanding AWS Costs
AWS Free Tier (What We're Using):
- • EC2 t2.micro: 750 hours/month for 12 months
- • Storage (EBS): 30 GB included in free tier
- • Data transfer: 1 GB outbound free per month
2. Set Up Billing Alerts (Optional)
Enable free tier usage alerts to get notified when approaching limits.
3. Monitor Your Usage (Optional)
Check the Free Tier dashboard in AWS to view your usage.
4. Cost Optimization Tips
- • Use only what's in this lab: t2.micro instance, 8 GB storage
- • Don't launch additional instances
- • Running one instance 24/7 uses only 744 hours - you're covered!
Troubleshooting
Cannot connect to EC2 via SSH
Check security group allows your IP
Flask container not accessible
Verify security group port 5001 is open
Seeing unexpected charges
Verify you selected t2.micro and haven't launched multiple instances
Lab 7 Summary - What You Deployed
Congratulations! You've deployed a complete production AI application to the cloud.
✅ Cloud Deployment Skills Gained
- Vercel Deployment: Production Next.js hosting with automatic builds
- AWS EC2: Virtual machine management and Docker deployment
- Cloud Architecture: Multi-service cloud infrastructure
- Environment Management: Secure production configuration
- Free Tier Management: Understanding AWS free tier limits
Key Takeaway: AWS free tier covers everything in this lab - no charges when following instructions. Free tier is valid for 12 months from AWS account creation.
📝 Test Your Knowledge
Complete the Lab 7 quiz to test your understanding of cloud deployment concepts with AWS EC2 and Vercel.
Take Lab 7 Quiz →