EBS & EFS
EC2 instances need disks. Amazon EBS provides block storage volumes that behave like a hard drive attached to one server, and Amazon EFS provides a shared file system that many servers can use at once. Knowing which to use, and how they differ from S3, is a core cloud skill.
Block, file and object storage
| Type | AWS service | How you use it | Typical use |
|---|---|---|---|
| Block | EBS | A raw disk you format and mount on one instance | Operating system disks, databases you run yourself |
| File | EFS (and FSx) | A shared folder mounted over the network by many instances | Shared uploads, content management systems, home directories |
| Object | S3 | Whole files over an HTTP API | Media, backups, data lakes, static websites |
Amazon EBS
An EBS volume lives in one Availability Zone and attaches to an instance in that same AZ. Data survives stopping the instance, and the volume can be detached and attached to another instance. Most volumes attach to one instance at a time (io1 and io2 volumes support a special Multi-Attach mode).
| Volume type | Kind | Use it for |
|---|---|---|
| gp3 | General purpose SSD | The default: boot disks and most workloads; performance can be set separately from size |
| io2 Block Express | Provisioned IOPS SSD | Demanding databases needing consistent high performance |
| st1 | Throughput-optimised HDD | Large sequential workloads such as log processing |
| sc1 | Cold HDD | Rarely accessed data at the lowest EBS price |
Adding a data volume
Create a 20 GiB gp3 volume in the same AZ as your instance and attach it (IDs are placeholders):
aws ec2 create-volume --availability-zone eu-west-1a --size 20 \
--volume-type gp3 --encrypted \
--tag-specifications "ResourceType=volume,Tags=[{Key=Name,Value=shop-data}]"
aws ec2 attach-volume --volume-id vol-0123456789abcdef0 \
--instance-id i-0abc1234def567890 --device /dev/sdf
Then, on the instance, find, format and mount it. On modern instances the volume appears as an NVMe device. Example output, shortened:
lsblk
sudo mkfs -t xfs /dev/nvme1n1 sudo mkdir /data sudo mount /dev/nvme1n1 /data df -h /data
mkfs erases everything on the device. Only run it on a brand-new, empty volume, and double-check the device name. To mount automatically after a reboot, add an entry to /etc/fstab using the volume's UUID.
Snapshots
A snapshot is a point-in-time backup of a volume, stored redundantly within the Region. Snapshots are incremental: after the first, only changed blocks are saved. You can create a new volume from a snapshot in any AZ of the Region, or copy it to another Region for disaster recovery.
aws ec2 create-snapshot --volume-id vol-0123456789abcdef0 \
--description "shop-data before upgrade"
Automate snapshots with Amazon Data Lifecycle Manager or AWS Backup rather than relying on memory.
Some instance types also have instance store: very fast disks physically attached to the host. Their data is lost when the instance stops or terminates, so use them only for caches and temporary data.
Amazon EFS
EFS is a managed NFS file system for Linux. It grows and shrinks automatically as you add and remove files, and you pay for what you store. Its key advantage: instances in several AZs can mount it at the same time. You create mount targets in each AZ, and instances connect to the one in their own AZ.
On Amazon Linux, install the EFS mount helper and mount the file system (the ID is a placeholder; the instance's security group must be allowed to reach the mount target on NFS port 2049):
sudo dnf install -y amazon-efs-utils sudo mkdir -p /mnt/uploads sudo mount -t efs -o tls fs-0123456789abcdef0:/ /mnt/uploads
A county government runs its document portal on three EC2 instances in an Auto Scaling group. Citizens upload scanned forms. If uploads went to each server's EBS disk, a form uploaded to server A would be missing on server B. Mounting one EFS file system on all servers (or, often better, storing uploads in S3) solves this.
EFS offers storage classes (Standard, Infrequent Access and Archive) with lifecycle management to move cold files automatically. For Windows file shares, high-performance computing or NetApp and ZFS features, look at the Amazon FSx family.
Costs to watch
EBS charges for the provisioned size of each volume per GB-month, whether you use the space or not, and whether the instance is running or stopped. Unattached "available" volumes left behind after terminating instances, and old snapshots, quietly add up. Check EC2 → Volumes and Snapshots after practice sessions. EFS charges for the storage you actually use, plus some throughput and access charges.
Key points
- EBS is block storage for one instance in one AZ; gp3 is the default type.
- Snapshots back up EBS volumes incrementally and can be copied across Regions.
- EFS is a shared, elastic NFS file system that instances in many AZs can mount together.
- Instance store is fast but temporary.
- Delete unused volumes and snapshots, because provisioned EBS storage is always billed.
Tip: use the ← and → keys to move between pages.
