Home ☁️ Cloud AWS EC2

What is
AWS EC2?

Amazon's virtual computer rental service — explained from a curious beginner's first question all the way to how a professional architect designs elastic, fault-tolerant systems with it.

📅 Updated 2026 ⏱️ ~22 min read 🖥️ AWS · Cloud · Compute
🖥️

Virtual Compute

Rent CPUs & RAM on demand

🔧

Fully Configurable

OS, size, storage, network

Launches in Minutes

From zero to running server

📈

Auto Scales

Grows & shrinks with demand

🍳

The Simple Explanation

EC2 is a Mega-Kitchen You Rent by the Minute

Before cloud computing, a young boy named Leo wanted to start a restaurant. His first step was to buy a giant, expensive building and fill it with stoves, refrigerators, and heavy-duty sinks — all before serving a single meal. That enormous upfront investment is called Capital Expenditure (CapEx). If business was slow on a Tuesday, those giant ovens still sat there consuming electricity, doing nothing.

With EC2, Leo simply logs into a website and says: "I'd like to use one burner for exactly thirty minutes." Amazon says: "Certainly — that's two cents." When Leo finishes, he stops paying. This shift from CapEx to Operating Expenditure (OpEx) is the entire reason cloud computing exists.

⚠️ The 4 Problems of Traditional IT

Traditional ProblemCloud SolutionHow EC2 Fixes It
High Upfront CostPay-as-you-goPay only for the seconds you actually use compute
Slow Setup (weeks)Near-instant launchA running server in under 2 minutes from the console
Wasteful CapacityElasticityScale out to 1,000 instances; scale back to 1 automatically
Maintenance BurdenManaged InfrastructureAmazon owns the physical hardware, cooling, and repairs

🔤 Decoding the Name: E-C-2

🔧

E — Elastic

Stretch & Shrink

Like a rubber band — one computer today, a thousand tomorrow, and back to one next week.

🧠

C — Compute

Brain Power

CPUs that do the thinking and RAM (short-term memory) that keeps the work fast.

☁️

C — Cloud

Amazon's Data Centers

The physical machines live in Amazon's secure, global data centers — you access them over the internet.

🏢 Virtualization — The Apartment Building

Think of a large apartment building. The building is the physical server Amazon owns. Inside are many separate apartments — each with its own door, kitchen, and lock. The person in Apartment A cannot see inside Apartment B. These apartments are called Instances — your individual rented virtual computer. The building manager who ensures everyone gets a fair share of water and electricity is the Hypervisor — a special software layer that keeps every tenant isolated and secure.

📋 AMI — The Digital Blueprint

Before you can start a computer, you need to decide what's inside it. An Amazon Machine Image (AMI) is a pre-packaged set of instructions — like a "Save File" in a video game or a document template. It pre-loads your operating system, software, and configuration so you're not starting from scratch every time.

🔬 Data Science AMI

Pre-loaded with Python, Jupyter, TensorFlow, and math libraries. Ready for scientists in seconds.

🌐 Web Server AMI

Apache or Nginx pre-installed. Point your domain at it and your website is live.

🐧 Amazon Linux 2023

AWS's own Linux, optimized for EC2. The recommended starting point for all beginners.

⚙️ The Nitro System — Amazon's Secret Engine

In the old days, the Hypervisor software had to do everything — cook the food, answer the phone, wash the dishes, and guard the door. This made the cooking slow. Amazon's Nitro System fixes this by installing specialized Nitro Cards — tiny dedicated chips that each handle one chore. One card handles networking. One handles storage. One handles security. The result? The CPU you rent can focus 100% on your software, making instances dramatically faster and more secure.

🚗

The Simple Explanation

Choosing the Right Vehicle

Not every task needs the same power. You wouldn't drive a monster truck to pick up groceries, or try to move a house in a Mini Cooper. EC2 Instance Types are the different "vehicles" in Amazon's fleet — each built for a different job.

🏷️ Instance Families

FamilyAnalogyBest Use Case
General Purpose (T, M)🚗 The Family Car — good at everythingSmall websites, learning, simple apps
Compute Optimized (C)🏎️ The Sports Car — very fast CPU, less storageHigh-speed math, video processing, online gaming
Memory Optimized (R, X)🚛 The Moving Truck — massive RAM capacityGiant databases that hold millions of records in memory
Accelerated Computing (P, G)🔭 The Specialist Tool — built for one jobAI/ML training, 3D graphics rendering, deep learning
Storage Optimized (I, D)🏭 The Warehouse — built for fast disk I/OHigh-speed record-keeping for banks or streaming

💥 Burstable Instances — The Stamina Runner

The T family (t2.micro, t3.small) is special — these are called burstable instances. Think of a runner who earns stamina credits while walking and spends them on sprints.

🚶

Baseline Performance

The runner's normal walking speed. Steady, predictable.

🏃

Burst Mode

Full sprint when needed. Spends accumulated CPU credits.

Unlimited Mode

Keep sprinting even with no credits — at a small extra cost.

📍 Placement Groups — Choosing Your Neighbours

The physical location of your virtual computer inside Amazon's data center can matter enormously for performance and reliability. Placement Groups let you control this.

StrategyAnalogyWhy Use It?
ClusterEveryone in the same roomInstances need to talk to each other at ultra-low latency (e.g., HPC, big data)
SpreadEveryone in a different buildingMaximum resilience — if one host fails, only one instance is affected
PartitionGroups in different neighbourhoodsGiant distributed systems (Hadoop, Kafka) — balances speed and safety

CPU vs. RAM Balance by Instance Family

Each family is optimized for a different ratio of compute power to memory.

🎒

The Simple Explanation

Two Types of Storage: Backpack vs. Table

EC2 gives you two primary ways to store data. The EBS Backpack keeps your files safe and detachable — attach it to any computer, and your data travels with it. The Instance Store Table is lightning-fast but wiped clean the moment you leave the room.

💾 EBS — The Detachable Backpack

Elastic Block Store (EBS) is the most common storage for EC2. It is a persistent digital hard drive that keeps your data even when the instance is turned off. You can detach it from one instance and attach it to another — all your files come along for the ride.

Best All-Around

gp3 — General Purpose SSD

The High-Quality School Bag

Fast, reliable, and the cheapest way to get great performance. The recommended default for most workloads. Up to 16,000 IOPS and 1,000 MB/s throughput.

🏆 Pro Tier

io2 — Provisioned IOPS SSD

The Professional Survival Pack

For ultra-high-speed work: saving and opening files thousands of times per second. Used by critical databases (Oracle, SAP). Up to 256,000 IOPS.

🧳 High Throughput

st1 — Throughput Optimized HDD

The Large Suitcase with Wheels

Great for moving giant sequential files (raw video, log data) — not for random reads. Think of a big suitcase: perfect for bulk cargo, not quick access.

📦 Lowest Cost

sc1 — Cold HDD

The Attic Storage Box

The cheapest EBS option. For files you almost never access — compliance archives, historical backups. Slow retrieval, but pennies per GB.

🍽️ Instance Store — The Built-in Table

Instance Store is storage physically built into the server hardware. Think of it as a kitchen table — extremely fast to reach across and grab a knife. But the moment you stop or terminate the instance (leave the kitchen), the table is wiped completely clean. Anything left on the table is gone forever. This is why Instance Store is called ephemeral — temporary by nature.

✅ When to Use Instance Store

  • Temporary caches and buffers
  • Scratch space for big data processing
  • When raw I/O speed matters more than persistence

❌ Never Use Instance Store For

  • Customer data or databases
  • Any file you cannot afford to lose
  • Application state that must survive reboots

🔄 Instance Lifecycle States

Understanding instance states is critical for controlling costs. You pay differently depending on the state.

StateWhat's HappeningPaying for Compute?EBS Charges?
PendingInstance starting upNoNo
RunningInstance is on and active✅ Yes✅ Yes
StoppedInstance is off — files preservedNo✅ Yes
HibernatedSleep mode — RAM saved to diskNo✅ Yes
TerminatedDeleted forever — cannot be recoveredNoNo (usually deleted)
🏘️

The Simple Explanation

Your Gated Community in the Cloud

AWS is a giant city. A VPC (Virtual Private Cloud) is a piece of land you bought and fenced off. Inside your fence you decide where the houses (instances) go and who has a key to the gate. Security Groups are the bouncers at the door of each house.

🌐 VPC & Subnets

🌞

Public Subnet

The Front Yard

Connected to the main road — the internet can reach it. This is where your web servers live so people can visit your website.

🔒

Private Subnet

The Inside of the House

No doors to the outside world. Only resources already inside your VPC fence can access it. Perfect for databases and secret files.

Gateways & IP Addresses

ComponentAnalogyPurpose
Internet Gateway (IGW)The main community gateConnects your VPC to the real internet. Without it, instances are offline.
NAT GatewayA one-way security doorLets private instances download updates, but prevents internet traffic from entering.
Private IPYour internal house numberUsed only inside the VPC. Never visible to the outside world.
Public IPYour street addressWhat people on the internet use to find you. Changes if you stop and restart the instance.
Elastic IPA permanent phone numberA fixed public IP that never changes — stays even if you get a new instance.

🔐 Security: Three Layers of Protection

🗝️ Key Pairs — The Magic Keys

When you launch an EC2 instance, you don't create a password. You create a Key Pair. Amazon keeps the Public Key (the lock on the door). You download the Private Key — the only physical key in the world that can open that lock. You then use SSH (Secure Shell) — a secure encrypted language — to communicate with your Linux instance.

ssh -i "my-key.pem" ec2-user@your-instance-ip

🚪 Security Groups — The Bouncer

A Security Group is a virtual firewall — a bouncer at the door of your instance with a strict guest list. You tell the bouncer: "Only let messages in through Port 80 (website traffic)." Anyone trying to sneak in through Port 22 (SSH) is stopped unless they're on the list.

Common Inbound Rules

  • Port 22 — SSH (Your Private Key only)
  • Port 80 — HTTP (Public website)
  • Port 443 — HTTPS (Secure website)
  • Port 3306 — MySQL (Specific IPs only)

Key Rules

  • Stateful — return traffic is auto-allowed
  • Default: deny all inbound, allow all outbound
  • Changes take effect immediately
  • Multiple groups can be attached to one instance

🪪 IAM Roles — The ID Badge

Sometimes your EC2 instance needs to talk to other AWS services (like S3 storage). Instead of giving it a username and password (which could be stolen), you give it an IAM Role — a digital ID badge. It's like giving a delivery driver a badge that only opens the garage door. They can drop off packages, but they can't go into the kitchen or bedroom.

🍽️

The Simple Explanation

A Restaurant That Never Runs Out of Chefs

In a traditional system, if your one server broke, everything stopped. EC2 uses two powerful tools — an Elastic Load Balancer (the Head Waiter) and an Auto Scaling Group (a Magic Spell) — to ensure your application never goes down, no matter how many visitors arrive.

⚖️ Elastic Load Balancing (ELB)

If you have multiple instances running your application, you need a way to split the incoming traffic fairly. The Elastic Load Balancer is the Head Waiter who greets every customer and directs them to whichever chef (instance) is least busy — and skips any chef who is sick (unhealthy instance).

🧠

Application LB (ALB)

The Intelligent Waiter

Reads the customer's order (HTTP content). Routes /api requests to the API server and /images to the image server. Layer 7 routing.

Network LB (NLB)

The Ultra-Fast Waiter

Doesn't read orders — just moves people to open tables at lightning speed. Handles millions of requests per second with ultra-low latency.

🛡️

Gateway LB (GLB)

The Security Waiter

Makes every customer walk through a metal detector (firewall appliance) before entering. Integrates third-party security tools transparently.

Auto Scaling Groups (ASG) — The Magic Spell

An ASG is like a magic spell on your kitchen. You set three numbers: Minimum (the fewest chefs you'll ever have), Maximum (the most you're willing to pay for), and Desired (how many you want right now). The spell watches the kitchen. If the one chef gets overwhelmed (high CPU usage), it instantly spawns new chefs. When the rush is over, it sends the extra chefs home — and you stop paying.

📉

Minimum Size

Floor — always at least this many instances running

🎯

Desired Capacity

Current target — ASG maintains this count normally

📈

Maximum Size

Ceiling — never pay for more than this many instances

Scaling Triggers

Policy TypeHow It WorksBest For
Target TrackingKeep CPU at exactly 60% — add/remove to maintain the targetMost workloads. Simplest to set up.
Step ScalingCPU 60–80% → add 1 instance. CPU >80% → add 3 at onceWorkloads with big sudden spikes
Scheduled Scaling"Every Monday morning at 9am, add 5 instances"Predictable traffic (business hours, sale events)
Predictive ScalingML analyzes historical patterns and pre-scales before the rushRegular, recurring traffic patterns
🚀

The Simple Explanation

How to Launch Your First Instance (Step by Step)

Launching an EC2 instance takes about 90 seconds and 7 steps. Here's what each screen means — and how to pick smart options as a beginner.

🖱️ The Launch Instance Wizard

1

Name & Tags

Give your instance a clear name like Leo-Website-Server. Add tags (labels) to organize and track costs — e.g., Project: MyBlog, Environment: Production.

2

Choose an AMI (Blueprint)

For beginners, select Amazon Linux 2023 — the most modern and easy-to-use option. Always check for the Free Tier Eligible badge to avoid charges while learning.

3

Instance Type (Muscle)

Choose t2.micro or t3.micro for your first time — these are small, free for 750 hours/month for your first year, and perfect for learning.

4

Key Pair (Your Private Key)

Click "Create new key pair", give it a name, and download the .pem file. Treat this like a real house key — keep it safe on your laptop. If you lose it, you'll need to replace the instance.

5

Network Settings (Security Groups)

Check Allow SSH traffic so you can connect to your machine. Check Allow HTTP traffic if you're building a website so visitors can reach it.

6

Configure Storage

The default 8 GiB gp3 is perfect for beginners. The gp3 type is the newest and fastest standard storage — there's no reason to pick anything else for your first instance.

7

Advanced Details (The Secret Sauce)

IAM Instance Profile — attach a Role to give your computer an ID badge.
Termination Protection — turn ON to prevent accidental deletion (safety lock).
User Data — paste a startup script here and the instance runs it automatically on first boot. It's like leaving a to-do list on the counter for a new chef.

💰 Pricing Models — Choosing How to Pay

🚕 Most Flexible

On-Demand

The Taxi Meter

Pay by the second for exactly what you use. No commitment. No upfront payment. The most expensive rate — but perfect for unpredictable workloads or testing.

🏠 Up to 72% off

Reserved / Savings Plans

The Long-Term Lease

Commit to 1 or 3 years and get a massive discount — up to 72% cheaper than On-Demand. Like signing a long-term apartment lease instead of staying in a hotel every night.

✈️ Up to 90% off

Spot Instances

The Standby Flight Ticket

Amazon's spare capacity sold at 90% discount. The catch: Amazon can reclaim them with just a 2-minute warning. Perfect for batch jobs, rendering, and fault-tolerant workloads — never for critical databases.

🏛️ Compliance Grade

Dedicated Hosts

The Private Building

Rent an entire physical server — no other customer's workloads share your hardware. Very expensive, typically used by companies with strict regulatory or licensing requirements.

📊 Monitoring with CloudWatch

CloudWatch is the dashboard of your car — it shows you speed, fuel, and engine temperature at a glance. For EC2, it tracks metrics like CPU Utilization, Network In/Out, and Disk Read/Write. You can set Alarms: "If my CPU stays above 80% for more than 5 minutes, send me an email and launch a second instance automatically." This is how you build a self-managing system.

🧠

CPU Utilization

Is the computer working too hard?

🌐

Network In/Out

How much traffic is visiting your site?

💾

Disk Read/Write

Is the instance saving a lot of files?

Key Takeaway

EC2: The Engine of the Cloud

What once required a million-dollar data center can now be done by a student with a laptop. An Instance is just a virtual room in a giant building. An AMI is a recipe for success. Auto Scaling is a magic spell for growth. The cloud is not just for experts — it is a digital playground where the only limit is your creativity.

Explore More Topics →