Skip to content

Beginner · Compute and storage: EC2 and S3 · topic 11 of 50 · 25 min

Block and file storage: EBS, instance store and EFS

Explanation

Block storage (EBS) is a virtual hard disk for one instance in one Availability Zone. Instance store is a fast local disk that is wiped when the instance stops. File storage (EFS) is a shared network folder that many instances can use at once across zones. Object storage (S3) keeps files as objects you read over HTTPS.

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.

TypeAWS serviceAccessGood for
BlockEBS, instance storeOne instance (as a disk)Operating system, databases
FileEFS, FSxMany instances (NFS or SMB)Shared uploads, home folders, CMS content
ObjectS3Any app over HTTPSBackups, images, logs, data lakes
Think of it like this: Block storage is your own cupboard at home: only you use it and you arrange the shelves. File storage is the office shared drive: the whole team opens the same folders. Object storage is a bank locker hall: you hand over a sealed box with a label, and you get the whole box back when you ask by label.

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.

bash
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"
Create, attach, format, mount, then back up a gp3 volume. IDs are examples.

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.

bash
sudo dnf install -y amazon-efs-utils
sudo mount -t efs -o tls fs-0abc1234:/ /mnt/shared
Mounting EFS with the EFS mount helper and encryption in transit.

Amazon 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

  1. Is it temporary scratch data you can lose? Instance store.
  2. Is it accessed by apps over HTTPS, very large, or a backup or archive? S3.
  3. Must several servers share the same files? EFS (Linux) or FSx for Windows File Server (Windows).
  4. Otherwise, one server needs a disk (boot volume, database)? EBS, usually gp3.
Careful: Common mistakes: (1) Trying to attach an EBS volume to an instance in another AZ; take a snapshot and create a new volume in the target AZ. (2) Running mkfs on a volume that already has data, which wipes it; check with sudo file -s /dev/nvme1n1 first. (3) Keeping a database on instance store and losing it on stop. (4) Using EBS for files that three web servers must share; use EFS or S3. (5) Deleting an instance but leaving its extra volumes and old snapshots billing for years.

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

Block File Object

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)

Task 1 · Question

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?

Task 2 · Code · Python

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".

Task 3 · Practice

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

Question 1

1.Which storage loses its data when the instance is stopped?

Question 2

2.Three Linux web servers in two AZs must read and write the same upload folder. What fits best?

Question 3

3.What does "incremental" mean for EBS snapshots?

Question 4

4.What is the usual default general purpose EBS volume type today?

Question 5

5.A Windows application needs a shared SMB file share joined to Active Directory. Which service?

Read more (free)

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.

From EC2: virtual servers in the cloud

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.

From Amazon S3: buckets, objects and storage classes

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.

From Backups and disaster recovery

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.

From Azure compute and storage

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

  1. 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.
  2. Module 3 exam: Compute and storage, EC2 and S3 · 12 questions · 20 min, without help. 4 topics of this module still to finish first.
  3. Then the next module, Networking and databases: VPC and RDS. 50 topics left in the course before the final exam.

← Previous: EC2: virtual servers in the cloud