EC2 Introduction
What EC2 is, instance types, pricing models, and core concepts
What is EC2?
Amazon Elastic Compute Cloud (EC2) gives you resizable virtual machines (called instances) in the cloud. You pick the OS, CPU, RAM, storage, and networking β and you can launch one in under a minute.
Think of an EC2 instance as a VPS (Virtual Private Server) that you can start, stop, resize, or terminate at any time.
Instance Types
Instance names follow a pattern: family + generation + size
t3.microβ β βββ size: nano / micro / small / medium / large / xlarge / 2xlarge ...β ββββββ generation: 3 (newer = better price/performance)ββββββββ family: t = burstable (general purpose, cheapest)| Family | Optimized For | Examples |
|---|---|---|
t | Burstable general purpose | t3.micro, t4g.small |
m | Balanced compute/memory | m6i.large |
c | Compute (CPU heavy) | c7g.xlarge |
r | Memory (RAM heavy) | r6i.2xlarge |
g / p | GPU workloads | g4dn.xlarge |
i | Storage (NVMe SSD) | i4i.large |
For learning and small projects, t3.micro (free tier eligible) is your go-to.
Pricing Models
| Model | How it works | Save vs On-Demand | Best for |
|---|---|---|---|
| On-Demand | Pay by the hour/second, no commitment | β | Dev/test, unpredictable workloads |
| Reserved | Commit 1 or 3 years upfront | up to 72% | Production workloads you know you need |
| Spot | Bid on unused capacity | up to 90% | Batch jobs, can handle interruptions |
| Savings Plans | Commit to $/hour spend, flexible family | up to 66% | Flexible alternative to Reserved |
Key Concepts
AMI (Amazon Machine Image)
A snapshot/template of an OS + software. Used to launch instances.
- AWS provides official AMIs: Amazon Linux 2023, Ubuntu 22.04, Windows Server, etc.
- You can create your own custom AMI from a running instance.
Security Group
A stateful firewall attached to an instance β controls inbound and outbound traffic.
- Default: deny all inbound, allow all outbound.
- You open specific ports (e.g. 22 for SSH, 80 for HTTP, 443 for HTTPS).
Key Pair
SSH authentication for Linux instances. AWS stores the public key; you keep the private key (.pem file).
EBS Volume
Elastic Block Store β the βhard driveβ attached to your EC2 instance. Persists after instance stop (unlike instance store).
Elastic IP
A static public IP address you can attach to/detach from instances. Free while attached to a running instance.
Instance Lifecycle
Pending β Running β Stopping β Stopped β Terminated β Rebooting β- Stop β instance is off, EBS data is preserved, you still pay for EBS
- Terminate β instance deleted, root EBS deleted by default (data gone)
- Reboot β like a restart, stays in Running state, same IP
Whatβs Next
- Creating Your First EC2 Instance β launch, connect via SSH, and run your first server