Beginner 30 min read Module 2 of 8

EC2 - Virtual Servers

EC2 (Elastic Compute Cloud) gives you virtual computers in the cloud. Think of it as renting a computer that lives in an Amazon warehouse somewhere in the world.

What is EC2?

EC2 is Amazon's virtual server service. It lets you:

  • Launch a virtual computer in seconds
  • Choose the operating system (Windows, Linux, Ubuntu, etc.)
  • Pick the size (CPU, memory, storage) you need
  • Pay only for what you use (or use the free tier)
  • Scale up or down as your needs change

Your First Mission: Launch a Server

  1. Login to AWS and type EC2 in the search bar at the top. Click the EC2 result.
  2. Click "Launch Instance" (the big orange button).
  3. Name it: Call it My-First-Server.
  4. Choose an OS (AMI): Pick "Amazon Linux" or "Ubuntu" (both are free).
  5. Choose a free server (Crucial!): Under "Instance type", select t2.micro or t3.micro. This is the ONLY free tier server.
  6. Key pair (Login password) - MOST IMPORTANT STEP!
    • Scroll down to "Key pair (login)"
    • Click "Create new key pair"
    • Name it: my-aws-key
    • Choose RSA and .pem (Mac/Linux) or .ppk (Windows)
    • DOWNLOAD THIS FILE AND SAVE IT SOMEWHERE SAFE! You cannot download it again.
  7. Leave everything else as default (Don't change storage or network settings).
  8. Click "Launch Instance" at the bottom right.
CONGRATULATIONS! You just turned on a computer in a warehouse somewhere in the world! Wait 30 seconds for it to boot up.

Connect to Your Server

  1. Go back to the EC2 dashboard and click "Instances" on the left sidebar.
  2. You will see your server. Click the checkbox next to it.
  3. At the top, click the "Connect" button.
  4. AWS will open a new browser tab. Click the button that says "EC2 Instance Connect" and click "Connect".
  5. BOOM! A black terminal window will open in your browser. You are now literally typing commands into a real computer in the cloud.
  6. Test it out:
    • Type sudo su (to become the admin)
    • Type yum update -y (to update the software)
    Watch the text fly by. You are a cloud engineer now!

Exercise: Host a Website

Task: Install Nginx and host a simple website.

  1. Connect to your EC2 instance via SSH.
  2. Install Nginx: sudo yum install nginx -y
  3. Start Nginx: sudo systemctl start nginx
  4. Edit the default page: sudo nano /usr/share/nginx/html/index.html
  5. Change it to: Hello, my name is [Your Name]!
  6. Visit your server's Public IP address in your browser and see your live website!
  7. IMPORTANT: Terminate the server immediately when done!
Show Solution
# Connect to your EC2 instance
ssh -i my-aws-key.pem ec2-user@your-server-ip

# Install Nginx
sudo yum install nginx -y

# Start Nginx
sudo systemctl start nginx

# Enable Nginx to start on boot
sudo systemctl enable nginx

# Edit the default page
sudo nano /usr/share/nginx/html/index.html

# Replace with: Hello, my name is [Your Name]!

# Save with Ctrl+X, Y, Enter

# Find your public IP in the EC2 console
# Visit: http://your-public-ip

# DONE! Now TERMINATE your instance!

Important EC2 Concepts

Concept Description
AMI Amazon Machine Image - the operating system template
Instance Type The size of your server (CPU, RAM). t2.micro = 1 vCPU, 1GB RAM
Key Pair Your SSH password to log in. Keep it safe!
Security Group A firewall that controls traffic to your server
EBS Volume The hard drive of your server
Elastic IP A fixed public IP address that doesn't change
Key Takeaway

EC2 gives you virtual servers in the cloud. Always use the Free Tier (t2.micro or t3.micro), and always terminate your instances when you're done testing!