devops

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)
FamilyOptimized ForExamples
tBurstable general purposet3.micro, t4g.small
mBalanced compute/memorym6i.large
cCompute (CPU heavy)c7g.xlarge
rMemory (RAM heavy)r6i.2xlarge
g / pGPU workloadsg4dn.xlarge
iStorage (NVMe SSD)i4i.large

For learning and small projects, t3.micro (free tier eligible) is your go-to.


Pricing Models

ModelHow it worksSave vs On-DemandBest for
On-DemandPay by the hour/second, no commitmentβ€”Dev/test, unpredictable workloads
ReservedCommit 1 or 3 years upfrontup to 72%Production workloads you know you need
SpotBid on unused capacityup to 90%Batch jobs, can handle interruptions
Savings PlansCommit to $/hour spend, flexible familyup 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