Beginner · Compute and storage: EC2 and S3 · topic 11 of 50 · 25 min
Block and file storage: EBS, instance store and EFS
Explanation
Three kinds of storage
Before choosing a service, know the three shapes of storage. Block storage gives the operating system a raw disk split into blocks; you format it with a file system such as ext4 or XFS and use it like a laptop drive. File storage is a ready-made shared folder over the network, so many machines see the same files. Object storage keeps whole files as objects with a name (key) and metadata; you put and get them with web requests, but you do not edit a byte in the middle.
| Type | AWS service | Access | Good for |
|---|---|---|---|
| Block | EBS, instance store | One instance (as a disk) | Operating system, databases |
| File | EFS, FSx | Many instances (NFS or SMB) | Shared uploads, home folders, CMS content |
| Object | S3 | Any app over HTTPS | Backups, images, logs, data lakes |
EBS volumes
An EBS (Elastic Block Store) volume is a network disk that lives in one Availability Zone (AZ). It can be attached only to instances in that same AZ. It survives stop and start, and it is copied inside the AZ to protect against a single disk failing. Volume types:
- gp3: general purpose SSD and the usual default. It includes a baseline of 3,000 IOPS (input/output operations per second) and 125 MiB/s of throughput at any size, and you can pay to raise them separately.
- io2 (Block Express): provisioned IOPS SSD for busy databases that need steady, very high IOPS and higher durability.
- st1: throughput-optimised HDD for big sequential reads such as log processing. Cannot be a boot volume.
- sc1: cold HDD, the cheapest, for data you rarely read. Cannot be a boot volume.
You can grow a volume or change its type while it is in use. Maximum sizes and IOPS change over time, so check the EBS documentation for the current limits.
Snapshots and encryption
A snapshot is a point-in-time backup of a volume, stored by AWS in S3 behind the scenes (you do not see it in your buckets). Snapshots are incremental: the first one copies all used blocks, and later ones copy only blocks that changed. You can create a new volume from a snapshot in any AZ of the region, or copy the snapshot to another region for disaster recovery. That is also how you move a disk to another AZ.
EBS encryption uses AWS KMS keys. Data at rest, snapshots and data moving between the instance and the volume are all encrypted, with no change to your app. Turn on "EBS encryption by default" in each region you use so nobody forgets.
aws ec2 create-volume --availability-zone ap-south-1a --size 50 --volume-type gp3 --encrypted
aws ec2 attach-volume --volume-id vol-0abc1234 --instance-id i-0abc1234 --device /dev/sdf
# On the instance (Nitro types show the disk as nvme1n1)
lsblk
sudo mkfs -t xfs /dev/nvme1n1 # format ONLY a new, empty volume
sudo mkdir /data && sudo mount /dev/nvme1n1 /data
aws ec2 create-snapshot --volume-id vol-0abc1234 --description "before upgrade"Instance store: fast but temporary
Some instance types (those with a d in the name, and the i family) come with instance store: NVMe disks physically inside the host. They are very fast and included in the price, but the data is lost when the instance stops, terminates, or the hardware fails. It survives a reboot. Use it only for caches, scratch files and copies of data that also lives somewhere else.
EFS and FSx: shared file systems
Amazon EFS (Elastic File System) is a managed NFS file system for Linux. Many instances, in many AZs, mount it at the same time and see the same files. It grows and shrinks on its own and you pay per GB stored, so you never size it in advance. It has a Regional option that stores data across several AZs and a cheaper One Zone option, plus Infrequent Access and Archive storage classes with lifecycle rules.
sudo dnf install -y amazon-efs-utils
sudo mount -t efs -o tls fs-0abc1234:/ /mnt/sharedAmazon FSx gives you other popular file systems as a managed service: FSx for Windows File Server (SMB, for Windows apps and Active Directory), FSx for Lustre (very fast, for HPC and machine learning), FSx for NetApp ONTAP and FSx for OpenZFS.
How to choose
- Is it temporary scratch data you can lose? Instance store.
- Is it accessed by apps over HTTPS, very large, or a backup or archive? S3.
- Must several servers share the same files? EFS (Linux) or FSx for Windows File Server (Windows).
- Otherwise, one server needs a disk (boot volume, database)? EBS, usually gp3.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Block and file storage: EBS, instance store and EFS · 1/7
There are three shapes of storage: block, file and object. Each one fits different jobs.
Prefer a video by a teacher? Find free videos on “aws ebs vs efs vs s3 vs instance store explained” on YouTube ↗
In real life: A WordPress news site in Chennai
A Tamil news portal runs WordPress on three EC2 instances behind a load balancer. Each instance boots from its own 20 GB gp3 EBS volume. Uploaded photos go to an EFS file system mounted at the same path on all three servers, so an image uploaded through one server shows on all of them. The MySQL database runs on Amazon RDS, and nightly backups of exported files go to S3. A daily EBS snapshot policy keeps seven days of boot disk backups.
Practice (0/3 done)
Your EBS volume is in ap-south-1a and the new instance is in ap-south-1b. How do you get the data onto the new instance?
Write choose_storage(temporary, needs_filesystem, shared) that returns one of "instance store", "S3", "EFS" or "EBS". Rules, in this order: temporary scratch data goes to "instance store"; if the app does not need a file system (it can use web requests) use "S3"; if many instances share the files use "EFS"; otherwise "EBS".
Lab: create a 10 GB encrypted gp3 volume in the same AZ as a test instance, attach it, format it with XFS, mount it at /data, write a file, take a snapshot, then unmount, detach and delete the volume (keep or delete the snapshot on purpose).
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Amazon S3: buckets, objects and storage classesCompute and storage: EC2 and S3 · same module
- Securing and sharing S3 dataCompute and storage: EC2 and S3 · same module
- Backups and disaster recoveryHigh availability, scaling and disaster recovery
- Azure compute and storageMicrosoft Azure essentials
- Managed relational databases: RDS and AuroraNetworking and databases: VPC and RDS
- Designing for high availabilityHigh availability, scaling and disaster recovery
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
Which storage loses its data when the instance is stopped?
Answer: Instance store
Instance store disks are physically attached to the host and are wiped on stop or terminate.
Three Linux web servers in two AZs must read and write the same upload folder. What fits best?
Answer: Amazon EFS
EFS is a shared NFS file system that many instances in many AZs can mount at once.
What does "incremental" mean for EBS snapshots?
Answer: After the first, only changed blocks are stored
Later snapshots store only blocks that changed since the previous one, which saves cost.
What is the usual default general purpose EBS volume type today?
Answer: gp3
gp3 is the general purpose SSD with a baseline of 3,000 IOPS and 125 MiB/s included.
A Windows application needs a shared SMB file share joined to Active Directory. Which service?
Answer: FSx for Windows File Server
EFS is NFS for Linux. FSx for Windows File Server provides SMB shares with Active Directory.
You stop (not terminate) an EBS-backed instance. What happens?Related
Answer: The root volume is kept and you still pay for it
Stopping ends the compute charge but the EBS volumes remain, and storage is still billed.
Which command uploads only new or changed files from a local folder to a bucket?Related
Answer: aws s3 sync
sync compares source and destination and copies only what is different.
In which DR strategy is a smaller but fully working copy of the whole system always running in the recovery region?Related
Answer: Warm standby
Warm standby runs a scaled-down full copy that is scaled up during a disaster.
Which redundancy keeps 3 copies across availability zones AND copies in a paired region?Related
Answer: GZRS
GZRS is ZRS in the primary region plus asynchronous copies in the secondary region.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 2 more topics in “Compute and storage: EC2 and S3” before its exam: Amazon S3: buckets, objects and storage classes, Securing and sharing S3 data.
- Module 3 exam: Compute and storage, EC2 and S3 · 12 questions · 20 min, without help. 4 topics of this module still to finish first.
- Then the next module, Networking and databases: VPC and RDS. 50 topics left in the course before the final exam.