Sub topic 1
What Amazon EBS is and how it works
Prerequisites
This chapter assumes you know the basic EC2 concepts: instances, AMIs and Availability Zones. You should be comfortable with the Linux command line and have used the AWS CLI or the Management Console. Basic knowledge of file systems and disk partitions helps in later chapters.
What EBS is
Amazon Elastic Block Store (EBS) provides block storage volumes for EC2 instances. A block device is a raw disk. The operating system formats it with a file system, such as XFS or ext4, and mounts it like a local drive.
EBS volumes are network-attached. The storage does not sit inside the host server that runs your instance. It lives on a separate storage service in the same Availability Zone, and the instance reaches it over the network. This design gives EBS three properties:
- Persistence. Data on a volume survives instance stop and start. A non-root volume also survives instance termination, because its DeleteOnTermination flag is off by default.
- Detachability. You can detach a volume from one instance and attach it to another.
- Independent management. You can resize a volume, change its type, snapshot it, and encrypt it without changing the instance.
How it works
Each volume exists in a single Availability Zone. EBS replicates the data within that zone, so a failure of one underlying component does not lose the volume. It does not replicate across zones. To protect against the loss of a zone, you take snapshots, which are stored durably in a Region-level store (Amazon S3, managed by EBS). You can then create a new volume from a snapshot in any zone of the Region.
A volume attaches to an instance in the same Availability Zone. On Nitro-based instances, the volume appears as an NVMe device, for example /dev/nvme1n1, even if you named it /dev/sdf when attaching it.
Volume families at a glance
EBS offers SSD-backed and HDD-backed volume types. SSD types suit workloads with many small reads and writes, such as boot volumes and databases. HDD types suit large, sequential workloads, such as log processing. The next chapters cover the choice in detail.
| Family | Types | Typical use |
|---|---|---|
| General purpose SSD | gp3, gp2 | Boot volumes, general workloads |
| Provisioned IOPS SSD | io2, io1 | Latency-sensitive databases |
| Throughput-optimized HDD | st1 | Big data, log processing |
| Cold HDD | sc1 | Infrequently accessed data |
A first look at the CLI
This command creates an encrypted 100 GiB gp3 volume in us-east-1a. It states the baseline performance explicitly.
aws ec2 create-volume \
--availability-zone us-east-1a \
--volume-type gp3 \
--size 100 \
--iops 3000 \
--throughput 125 \
--encrypted \
--tag-specifications 'ResourceType=volume,Tags=[{Key=Name,Value=data-vol}]'The output includes a VolumeId, which you use for every later operation. A new volume starts in the creating state and becomes available when it is ready to attach.
Common mistakes
- Wrong Availability Zone. Attaching fails if the instance and volume are in different zones. Create the volume in the instance's zone, or restore it from a snapshot into that zone.
- Treating a volume as a backup. A volume is one copy inside one zone. Snapshots are the backup mechanism.
- Assuming a new volume is usable. A blank volume has no file system. You must format and mount it before use.
Exercise
An instance runs in us-east-1a. You create a volume in us-east-1b and try to attach it. What happens, and how do you get the data onto the instance?
Show answer
The attach fails because a volume can attach only to an instance in the same Availability Zone. Create a snapshot of the volume, create a new volume from that snapshot in us-east-1a, and attach the new volume.