AWS EC2 โ Virtual Servers
Spin up a Linux server in the cloud in minutes โ the workhorse of AWS.
EC2 (Elastic Compute Cloud) gives you virtual servers โ โinstancesโ โ that you can launch in minutes and shut down when youโre done. Itโs the service youโll use to run applications, host websites, and practise everything you learned in the Linux section, in the cloud.
๐ฏ Learning Objectives
By the end of this lesson you will:
- Understand what an EC2 instance is
- Know the key choices when launching one
- Connect to an instance with SSH
- Understand security groups and cost control
Anatomy of an EC2 Instance
When you launch an instance you choose:
| Choice | What it means |
|---|---|
| AMI | The base image โ the OS and pre-installed software (e.g. Ubuntu 24.04) |
| Instance type | The size โ vCPUs and memory (e.g. t3.micro) |
| Key pair | The SSH key youโll use to log in |
| Security group | A virtual firewall controlling inbound/outbound traffic |
| Storage (EBS) | The virtual hard disk attached to the instance |
๐ก Free-tier friendly
The t2.micro / t3.micro instance types are included in the AWS Free Tier for a set number of hours per month โ perfect for practising without a bill.
Security Groups = Firewalls
A security group controls what traffic can reach your instance. A typical web server:
Inbound rules
โโโโโโโโโโโโโ
SSH (port 22) โ your IP only # you can log in
HTTP (port 80) โ 0.0.0.0/0 # anyone can browse
HTTPS (port 443) โ 0.0.0.0/0โ Don't open SSH to the world
Setting SSH (port 22) to 0.0.0.0/0 exposes your login to the entire internet and invites constant brute-force attempts. Restrict port 22 to your IP address only.
Connect with SSH
Remember SSH from the Linux section? This is where it pays off. Use the key pair you selected at launch:
chmod 400 my-key.pem
ssh -i my-key.pem ubuntu@<instance-public-ip>Youโre now inside a Linux server running in an AWS data centre.
Control the Cost
# From the CLI (or the console):
aws ec2 stop-instances --instance-ids i-0abc123 # stop = no compute charge
aws ec2 start-instances --instance-ids i-0abc123 # start it again later
aws ec2 terminate-instances --instance-ids i-0abc123 # delete permanentlyโ Stop or terminate when you're done
A running instance is billed by the second. Stop it to pause compute charges, or terminate it to remove it entirely. Forgetting a running instance is the classic โsurprise AWS billโ.
๐งช Hands-on Lab
Launch and Connect to an Instance
- Launch a
t3.microUbuntu instance in the console. - Create/select a key pair and download the
.pemfile. - Set a security group: SSH from your IP, HTTP from anywhere.
- Connect via
ssh -i key.pem ubuntu@<public-ip>and rununame -a. - Terminate the instance when finished.
๐ง Knowledge Check
What is a security group in EC2?
You've finished practising. How do you avoid being charged for compute?
๐ผ Interview Preparation
What's the difference between stopping and terminating an EC2 instance?
๐ Section Complete
You can now launch, secure, connect to, and manage EC2 instances โ and keep costs under control. Youโve covered the AWS essentials: cloud concepts, IAM, and compute. Next, we explore the other major cloud: Microsoft Azure.