Sub topic 12
Instance store: fast but temporary
This chapter assumes you can launch an instance with the AWS CLI and that you know what an EBS volume is. It covers the second kind of block storage an instance can use.
What instance store is
Instance store is disk storage physically attached to the host computer that runs your instance. EBS volumes are network-attached. Because instance store is local, it has low latency and high throughput. It adds no separate charge, because its cost is part of the instance type's price.
The trade-off is that the data is temporary. It is tied to the host, not to your account.
When data survives
| Event | Instance store data |
|---|---|
| Reboot | Kept |
| Stop | Lost |
| Hibernate | Lost |
| Terminate | Lost |
| Underlying drive fails | Lost |
Treat the volume as scratch space. Any data on it must be reproducible or replicated elsewhere.
Which instances have it
Only some instance types include instance store. Many have a "d" in the family name, such as m5d or c5d. Storage-optimized families such as i3 and i4i are built around it. Check what a type offers before you launch:
aws ec2 describe-instance-types \
--filters Name=instance-storage-supported,Values=true \
--query 'InstanceTypes[?starts_with(InstanceType, `m5d.`)].[InstanceType,InstanceStorageInfo.TotalSizeInGB]' \
--output tableYou choose the volumes at launch. You cannot add instance store to a running instance later. You also cannot snapshot it, because snapshots apply only to EBS.
Using the volume
On current Nitro-based types, instance store appears as an NVMe device. It is not formatted or mounted automatically. Find the device, then format and mount it on the instance:
lsblk
sudo mkfs -t xfs /dev/nvme1n1
sudo mkdir /scratch
sudo mount /dev/nvme1n1 /scratchDevice names vary. Use lsblk to tell the instance store disk from the EBS root volume before you run mkfs. Formatting the wrong device destroys its data. A mount does not persist across a stop and start, so repeat these steps at boot, for example from user data.
NVMe instance store volumes on Nitro instances are encrypted by default, and the key is destroyed when the instance stops or terminates.
Choosing between EBS and instance store
Use instance store for caches, buffers, temporary sort files, and data that is replicated across nodes, such as a distributed database where losing one node is tolerable. Use EBS for anything you cannot afford to lose.
Common mistakes:
- Putting the only copy of important data on instance store.
- Expecting it to survive a stop and start, which moves the instance to a different host.
- Running
mkfson the wrong device. - Assuming every instance type has instance store.
Exercise
An m5d.large instance holds a 30 GB cache on its instance store volume. You stop the instance to change its type, then start it again. What happens to the cache, and how could you avoid rebuilding it by hand?
Show answer
The cache is lost, because stopping erases instance store data and the instance restarts on a different host. To avoid manual work, rebuild the cache automatically at boot, for example with a user data script that formats, mounts, and repopulates the volume from a durable source such as EBS or S3.