← Labs

Lab 7: Cloud Deployment with AWS

Advanced
Level
AWS EC2 + Vercel
Technology

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:

text
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:

  1. Go to vercel.com
  2. Click "Sign Up" or "Login"
  3. Choose "Continue with GitHub"
  4. Authorize Vercel to access your repositories

3. Configure Environment Variables

Before deploying, add your environment variables in Vercel.

4. Deploy to Vercel

  1. Click "Deploy" button
  2. Wait 2-3 minutes for build to complete
  3. 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

  1. Go to aws.amazon.com
  2. Click "Sign In to the Console"
  3. 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.

bash
# Mac/Linux - Set permissions
chmod 400 ~/.ssh/mlops-service-key.pem

4. 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

  1. Go to EC2 Dashboard
  2. 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

bash
# Connect via SSH
ssh -i ~/.ssh/mlops-service-key.pem ubuntu@YOUR_EC2_PUBLIC_IP

6. Install Docker on EC2

bash
# Update and install Docker
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io

7. 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

bash
# Run container
docker run -d \
  --name mlops-service \
  --restart unless-stopped \
  -p 5001:5001 \
  --env-file .env \
  mlops-service:latest

10. Test Flask Service

bash
# Test health endpoint
curl http://YOUR_EC2_PUBLIC_IP:5001/health

Part E: Connect Services

Link Vercel and AWS together for production system

1. Update Vercel Environment

  1. Go to Vercel project settings
  2. Update MLOPS_SERVICE_URL to your EC2 IP
  3. 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 →