EBS Volumes

Elastic Block Store provides durable disk volumes that attach to EC2 instances like a hard drive.

Amazon EBS (Elastic Block Store) gives an EC2 instance a persistent block-storage volume — effectively a virtual hard drive. Unlike the instance itself, an EBS volume survives a stop/start and can be detached and reattached.

Key facts

  • A volume lives in one Availability Zone and can attach to instances in that AZ.
  • Volume types trade performance for cost: gp3 (general SSD), io2 (high-IOPS SSD), st1 (throughput HDD).
  • You can take point-in-time snapshots to S3 for backup, and create new volumes from them.

EBS vs instance store

Some instance types include instance store — fast local disk that is ephemeral and lost on stop/terminate. Use EBS for anything you need to keep.

Example

Example · bash
# Create a 20 GiB gp3 volume in a specific AZ
aws ec2 create-volume --volume-type gp3 --size 20 \
  --availability-zone us-east-1a

# Attach it to an instance as /dev/sdf
aws ec2 attach-volume --volume-id vol-0123456789abcdef0 \
  --instance-id i-0123456789abcdef0 --device /dev/sdf

# Back it up with a snapshot
aws ec2 create-snapshot --volume-id vol-0123456789abcdef0 \
  --description "nightly backup"

When to use it

  • A database server running on EC2 uses a gp3 EBS volume as its data directory, providing persistent storage that survives instance reboots.
  • A backup job creates an EBS snapshot nightly and stores it in S3, enabling point-in-time recovery of a production database volume.
  • A developer detaches an EBS volume from a terminated instance and reattaches it to a new one to recover data after an accidental termination.

More examples

Create and Attach an EBS Volume

Creates a 50 GiB gp3 volume and attaches it to an EC2 instance as a block device for use as a data disk.

Example · bash
# Create a 50 GiB gp3 volume in the same AZ as your instance
VOL=$(aws ec2 create-volume \
  --availability-zone us-east-1a \
  --size 50 \
  --volume-type gp3 \
  --query VolumeId --output text)

# Attach it as /dev/sdf
aws ec2 attach-volume \
  --volume-id $VOL \
  --instance-id i-0123456789abcdef0 \
  --device /dev/sdf

Snapshot EBS Volume for Backup

Creates an incremental snapshot of an EBS volume to S3 for backup, tagged for easy identification and retention policies.

Example · bash
aws ec2 create-snapshot \
  --volume-id vol-0abc1234def56789a \
  --description "Daily backup $(date +%Y-%m-%d)" \
  --tag-specifications 'ResourceType=snapshot,Tags=[{Key=Type,Value=daily-backup}]'

Restore Volume from Snapshot

Creates a new EBS volume from a snapshot, restoring the exact data state at the time the snapshot was taken.

Example · bash
aws ec2 create-volume \
  --snapshot-id snap-0abc1234def56789a \
  --availability-zone us-east-1a \
  --volume-type gp3

Discussion

  • Be the first to comment on this lesson.