โ† Back to Home
๐Ÿ–ฅ๏ธ

AWS EC2 โ€” Virtual Servers

Spin up a Linux server in the cloud in minutes โ€” the workhorse of AWS.

โฑ12 min read๐Ÿ“šDevOps Fundamentals

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:


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:

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

bash
chmod 400 my-key.pem
ssh -i my-key.pem ubuntu@<instance-public-ip>
bash โ€” 80ร—24
student@devops:~$ssh -i my-key.pem ubuntu@54.72.10.5

Youโ€™re now inside a Linux server running in an AWS data centre.


Control the Cost

bash
# 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

  1. Launch a t3.micro Ubuntu instance in the console.
  2. Create/select a key pair and download the .pem file.
  3. Set a security group: SSH from your IP, HTTP from anywhere.
  4. Connect via ssh -i key.pem ubuntu@<public-ip> and run uname -a.
  5. Terminate the instance when finished.

๐Ÿง  Knowledge Check

Knowledge Check

What is a security group in EC2?

Knowledge Check

You've finished practising. How do you avoid being charged for compute?


๐Ÿ’ผ Interview Preparation

Interview Q&A

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.

Up Next

Introduction to Azure

You've mastered this lesson. Continue your journey to becoming a DevOps Engineer.

Start Next Lessonโ†’