Databases, build caches and legacy apps need real disks and file systems, and choosing the wrong one costs money or availability.
EBS volumes are network-attached block devices for EC2. A volume lives in one AZ and normally attaches to one instance at a time; it persists independently of the instance.
Volume types:
- gp3: the default general-purpose SSD. It includes 3,000 IOPS and 125 MiB/s regardless of size, and you can buy more IOPS and throughput independently. Prefer it over the older gp2, where performance scaled with size.
- io2 Block Express: provisioned-IOPS SSD for demanding databases, with higher durability.
- st1 / sc1: throughput-optimised and cold HDD for big sequential workloads.
You can grow a volume or change its type online with modify-volume, then extend the partition and file system inside the OS.
Snapshots are point-in-time, incremental backups stored regionally in S3. Restore one to create a volume in any AZ of the Region, or copy it to another Region for disaster recovery. Volumes restored from snapshots load blocks lazily, so first reads are slow unless you pre-warm or use Fast Snapshot Restore. Turn on EBS encryption by default for the account; AWS Backup or Data Lifecycle Manager can schedule snapshots.
EFS is a managed NFS file system that many instances, containers and Lambda functions mount at once, across AZs. It grows and shrinks automatically and bills per GB stored, with Elastic throughput by default. Use it for shared content, not as a database disk. Windows shares, Lustre and NetApp ONTAP are available as FSx.
Instance store disks are physically attached and very fast, but vanish when the instance stops.
Example
aws ec2 enable-ebs-encryption-by-default
VOL=$(aws ec2 create-volume --availability-zone eu-west-1a --size 100 \
--volume-type gp3 --iops 6000 --throughput 250 --query VolumeId --output text)
aws ec2 wait volume-available --volume-ids "$VOL"
aws ec2 attach-volume --volume-id "$VOL" --instance-id i-0a1b2c3d4e5f67890 --device /dev/sdf
# Grow online, then on the instance: sudo xfs_growfs /data
aws ec2 modify-volume --volume-id "$VOL" --size 200
SNAP=$(aws ec2 create-snapshot --volume-id "$VOL" --description nightly \
--query SnapshotId --output text)
aws ec2 copy-snapshot --region eu-central-1 \
--source-region eu-west-1 --source-snapshot-id "$SNAP" # DR copy
# Shared file system for many instances or containers
aws efs create-file-system --encrypted --throughput-mode elastic \
--tags Key=Name,Value=shared-media --query FileSystemId --output text
# fs-0a1b2c3d -> sudo mount -t efs fs-0a1b2c3d:/ /mnt/sharedRemember
- EBS = one-AZ block device; gp3 is the default with tunable IOPS and throughput
- Snapshots are incremental, regional, and copyable across Regions
- EFS = shared NFS across AZs for many clients
- Instance store is fast but ephemeral
Watch out for
- Expecting an EBS volume to attach to an instance in another AZ; restore a snapshot there instead.