AWS EBS Volumes
/tldr: Network-attached, persistent block storage for EC2 instances.
1. Core Concepts: Block Storage
EBS Volumes are essentially virtual hard drives attached to an EC2 instance over the network. Unlike S3 (Object Storage), EBS is **Block Storage**, meaning the operating system sees it as a raw, formatted disk.
Persistence and Lifecycle
- **Persistent:** EBS data persists even after the EC2 instance is stopped or terminated (unless configured otherwise).
- **Boot Volume:** The root volume (OS drive) is always an EBS volume. By default, it is deleted when the instance is terminated.
- **One-to-One:** A volume can only be attached to a single EC2 instance at a time (unless using Multi-Attach on specific IOPS types).
AZ Dependency (Crucial)
EBS volumes are AZ-specific. They must reside in the same Availability Zone as the EC2 instance they are attached to.
- **Durability:** EBS is replicated within its AZ (99.8% - 99.9% availability), but it does **not** span AZs automatically.
- **Migration:** To move a volume across AZs, you must create a **Snapshot** first.
2. Volume Types: Performance Tiers
EBS offers different volume types optimized for transactional workloads (SSD) or sequential throughput (HDD).
SSD-Backed (Transactional)
Optimized for frequent read/write, high IOPS.
- **General Purpose (GP3):** Default choice, cost-effective for most workloads. Baseline 3,000 IOPS and 125 MB/s throughput, burstable.
- **Provisioned IOPS (IO2):** Highest performance, mission-critical applications (e.g., large databases). You explicitly define IOPS and throughput targets.
HDD-Backed (Throughput)
Optimized for large, sequential data access.
- **Throughput Optimized (ST1):** Frequently accessed, large sequential workloads (e.g., ETL, logs, data warehousing).
- **Cold HDD (SC1):** Least expensive, infrequent access, large sequential data (e.g., archival storage where data access is rare).
3. Snapshots: Backup & Recovery
An EBS **Snapshot** is the key to backing up and moving EBS data.
How They Work
- **Incremental:** Only blocks that have changed since the last snapshot are stored. This saves storage space and reduces backup time.
- **Storage Location:** All snapshots are transparently stored on **AWS S3**.
- **First Snapshot:** The first snapshot is a full copy; subsequent snapshots only store the delta.
Use Cases
- **Recovery:** Restore a volume from a snapshot if the primary volume fails.
- **Cross-AZ Migration:** Copy a snapshot to a different AZ, then create a new volume from that copied snapshot.
- **AMI Creation:** Snapshots are used in the process of creating custom Amazon Machine Images (AMIs).
# AWS CLI command to create a snapshot
aws ec2 create-snapshot --volume-id vol-0a1b2c3d4e5f6g7h8 --description "Daily backup of WebApp Volume"
EBS is the performance engine; Snapshots are the safety net.