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
-
Login to AWS and type
EC2in the search bar at the top. Click the EC2 result. - Click "Launch Instance" (the big orange button).
-
Name it: Call it
My-First-Server. - Choose an OS (AMI): Pick "Amazon Linux" or "Ubuntu" (both are free).
-
Choose a free server (Crucial!): Under "Instance type",
select
t2.microort3.micro. This is the ONLY free tier server. -
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.
- Leave everything else as default (Don't change storage or network settings).
- 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
- Go back to the EC2 dashboard and click "Instances" on the left sidebar.
- You will see your server. Click the checkbox next to it.
- At the top, click the "Connect" button.
- AWS will open a new browser tab. Click the button that says "EC2 Instance Connect" and click "Connect".
- BOOM! A black terminal window will open in your browser. You are now literally typing commands into a real computer in the cloud.
-
Test it out:
- Type
sudo su(to become the admin) - Type
yum update -y(to update the software)
- Type
Exercise: Host a Website
Task: Install Nginx and host a simple website.
- Connect to your EC2 instance via SSH.
- Install Nginx:
sudo yum install nginx -y - Start Nginx:
sudo systemctl start nginx - Edit the default page:
sudo nano /usr/share/nginx/html/index.html - Change it to:
Hello, my name is [Your Name]! - Visit your server's Public IP address in your browser and see your live website!
- 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!