Choosing and Protecting Block Storage with Amazon EBS
This lesson explains how Amazon EBS provides block storage volumes, which act as virtual hard drives for a single EC2 instance and hold operating systems and databases that need low-latency disk access.
Learning outcomes
After completing this lesson, you will be able to:
- Choose between Amazon EBS, Amazon EFS and Amazon S3 from how an application accesses its data.
- Distinguish the SSD and HDD volume families and the workloads each suits.
- Explain how snapshots back up volumes and move them between Availability Zones and Regions.
- Describe how an existing unencrypted volume is encrypted.
EBS, EFS or S3?
AWS offers three storage models for applications, and the choice follows from how the data is accessed.
Amazon EBS provides block storage: a volume behaves like a disk attached to one EC2 instance, which formats it with a file system. It offers the lowest latency and suits boot volumes and databases running on an instance. A volume exists in one Availability Zone and can attach only to instances in that zone; snapshots, stored in S3, copy it to other zones or Regions.
Amazon EFS provides a shared file system that many EC2 instances, ECS tasks and Lambda functions mount at the same time over the NFS protocol, across Availability Zones. It grows and shrinks automatically, so it suits content that several servers must read and write, such as uploaded files for a web application or a shared model directory. Amazon S3 provides object storage reached through an HTTPS API rather than a file system. It scales without limit, is the cheapest of the three for large volumes, and is the usual choice for application data, backups and static content. The following table summarises the three models.
Volume types
Amazon EBS volume types fall into two families. SSD volumes are optimised for small random reads and writes, measured in IOPS, which databases and boot volumes need. HDD volumes are optimised for large sequential reads and writes, measured in throughput, at a lower price, and cannot be used as boot volumes.
gp3 is the general purpose SSD and the default choice. Every volume includes a baseline of 3,000 IOPS and 125 MiB/s, and more IOPS and throughput can be provisioned independently of the volume size, unlike the older gp2, whose performance grew with size. io2 Block Express provides provisioned IOPS SSD storage with the highest performance and durability, for databases that need sustained, consistent IOPS, and supports Multi-Attach. st1 is a throughput-optimised HDD for large sequential workloads such as log processing and data warehouses, and sc1 is a cold HDD for large, rarely accessed data at the lowest cost. The following table summarises the types.
| Volume type | Use for |
|---|---|
| gp3 (general purpose SSD) | Most workloads; IOPS and throughput set independently of size |
| io2 / io2 Block Express (provisioned IOPS SSD) | Demanding databases needing very high, consistent IOPS |
| st1 (throughput-optimised HDD) | Large sequential workloads such as log processing |
| sc1 (cold HDD) | Infrequently accessed data at the lowest cost |
Snapshots
EBS snapshots back up volumes and allow them to be restored or copied. The following list describes how snapshots work.
- A snapshot is an incremental, point-in-time backup stored by AWS in S3.
- A volume is tied to its Availability Zone. To move data, snapshot it and create a new volume from the snapshot in another zone, or copy the snapshot to another Region or account first.
- Amazon Data Lifecycle Manager or AWS Backup automates snapshot schedules and retention.
Encryption
EBS volumes and snapshots can be encrypted with KMS, and EBS encryption by default encrypts every new volume in a Region. An existing unencrypted volume cannot be encrypted in place: snapshot it, copy the snapshot with encryption enabled, and create a new volume from the copy.
aws ec2 copy-snapshot --source-snapshot-id snap-0abc123 --source-region eu-west-1 \
--encrypted --kms-key-id alias/ebs-data --description "encrypted copy"Moving and encrypting a database volume
A self-managed database on EC2 stores its data on an unencrypted gp2 volume in eu-west-1a. The team must move it to an instance in eu-west-1b, encrypt it and improve its performance.
| Step | Action |
|---|---|
| 1 | Stop writes and create a snapshot of the volume |
| 2 | Copy the snapshot with --encrypted and a customer managed KMS key |
| 3 | Create a gp3 volume from the encrypted copy in eu-west-1b, setting IOPS and throughput independently of size |
| 4 | Attach the volume to the new instance and start the database |
Volumes cannot cross Availability Zones or be encrypted in place, so a snapshot is the route for both. Turning on EBS encryption by default prevents new unencrypted volumes from being created.
A volume in us-east-1a must be used by an instance in us-east-1b. How is this done?
Show answer
Create a snapshot of the volume and restore a new volume from it in us-east-1b. An EBS volume belongs to one Availability Zone, while snapshots are stored at Region level.
Exam Tips
Remember for the exam
- Low-latency disk storage for a single instance points to EBS.
- To move an EBS volume to another Availability Zone, snapshot it and create a new volume there.
- To encrypt an unencrypted volume, copy its snapshot with encryption and restore from the copy.
- gp3 is the default general-purpose choice; io2 suits databases that need very high IOPS.