Sub topic 12
Instance store: fast but temporary
This chapter assumes you can launch an instance with the AWS CLI, you know the instance states (running, stopped, terminated), and you have read the EBS chapter. It covers what instance store is, when its data disappears, how to use it, and when to choose it over EBS.
What instance store is
An instance store is a set of disks physically attached to the host server that runs your instance. It is not a network volume like EBS. Reads and writes go to local disks, usually NVMe SSDs, so you get high throughput and low latency.
The cost of that speed is durability. The storage belongs to the host, not to you. When the instance leaves that host, the data is gone.
- You do not pay a separate price for it. It is included in the hourly instance price.
- You cannot detach it and attach it to another instance.
- You cannot snapshot it.
- You cannot add it after launch. It exists only on instance types that include it, and its size is fixed by the type.
Which instance types have it
Instance store comes with specific families. Many general-purpose types, such as t3, have none. Others include it when the name carries a d, as in m5d, c5d, and r5d. Storage-optimized families such as i3, i4i, and d3 are built around it.
You can ask the API which types offer it and how much storage each has:
aws ec2 describe-instance-types \
--filters Name=instance-storage-supported,Values=true \
Name=instance-type,Values=m5d.* \
--query 'InstanceTypes[].[InstanceType,InstanceStorageInfo.TotalSizeInGB]' \
--output tableAn m5d.large, for example, has one 75 GB NVMe SSD. Check the size before you plan around it, because you cannot resize it without changing the instance type.
When the data survives and when it does not
Data on an instance store lives as long as the instance stays on the same host. The table shows what each event does.
| Event | Instance store data |
|---|---|
| Reboot (OS or API) | Kept |
| Stop | Lost |
| Hibernate | Lost |
| Terminate | Lost |
| Drive failure on the host | Lost |
| Host retirement or failure | Lost |
The reboot row surprises people. A reboot keeps the instance on its host, so files remain. A stop releases the host. When you start the instance again, it usually lands on a different host with empty, unformatted disks.
The data is also encrypted at rest. On current Nitro-based types, NVMe instance store volumes are encrypted by a hardware module with keys that are unique to the volume. The keys are destroyed when the instance stops or terminates, so another customer cannot read your old data from the same disk.
Using the volume
An NVMe instance store volume shows up in the guest operating system automatically on current instance types, but it has no filesystem. You format and mount it yourself. Launch an instance of a type that has one:
aws ec2 run-instances \
--image-id "$AMI_ID" \
--instance-type m5d.large \
--key-name my-key \
--security-group-ids sg-0123456789abcdef0 \
--subnet-id subnet-0123456789abcdef0 \
--metadata-options HttpTokens=required \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=tutorial-scratch}]'Older non-NVMe types needed an explicit mapping such as VirtualName=ephemeral0 in --block-device-mappings. For current NVMe types you can skip that step.
Then connect over SSH and run this script. It finds the instance store device by its model name, so it does not confuse it with the EBS root volume:
#!/bin/bash
set -euo pipefail
DEV=$(lsblk -dpno NAME,MODEL | awk '/Instance Storage/ {print $1; exit}')
if [ -z "$DEV" ]; then
echo "No instance store volume found" >&2
exit 1
fi
sudo mkfs.xfs -f "$DEV"
sudo mkdir -p /mnt/scratch
sudo mount "$DEV" /mnt/scratch
sudo chown "$USER": /mnt/scratch
df -h /mnt/scratchThe -f flag overwrites whatever is on the device. That is safe here because the device is empty. Never run this against an EBS data volume you care about.
Do not rely on fstab alone
After a stop and start, the new disk has no filesystem. A normal /etc/fstab entry would point at a filesystem that no longer exists, and a failed mount can stop the boot sequence. If you add a line, include the nofail option. A better approach is to run the format-and-mount script on every boot, for example from a systemd unit. User data runs only on first boot by default, so it does not cover the stop and start case.
Good and bad uses
Instance store fits data that you can recreate or that exists elsewhere:
- Caches and buffers
- Scratch space for sorting, video transcoding, or batch jobs
- Temporary files and swap
- Data that the application already replicates across nodes, such as Cassandra, Kafka, or a distributed file system
It does not fit data that exists only on that instance, such as a single-node database, uploaded user files, or logs you need after an incident. Those belong on EBS, with snapshots, or in a service such as S3.
A common pattern combines both: keep the working set on instance store, and write results to EBS or S3 when a job finishes.
Edge cases
- Instance store-backed AMIs. An older AMI format kept the root volume itself on instance store, loaded from S3. It cannot be stopped, only rebooted or terminated, and it is not recommended for new work. Use EBS-backed AMIs.
- Instance type changes. Resizing an instance means stopping it. Any instance store data is lost, and the new type may have a different amount of storage or none.
- Hardware failure is normal. Do not treat a drive failure as rare. Design as if the data can vanish at any time.
- Performance varies by type. Capacity and IOPS differ widely across families. Benchmark with a tool such as
fioon the type you plan to use.
Exercise
A team runs a single-node PostgreSQL server on an i4i instance and stores the data directory on the instance store volume for speed. The instance is stopped overnight to save cost. What happens, and what should they change?
Show answer
The data is lost when the instance stops, because the volume belongs to the host and the instance starts on a different host with empty disks. A drive or host failure would lose it too. They should move the data directory to an EBS volume and take regular snapshots, or add replication so another node holds a copy. Instance store may still hold temporary data, such as sort files.
Exercise
You reboot an m5d instance and find the files in /mnt/scratch are still there, but after stopping and starting it the mount point is empty and the device has no filesystem. Explain both results.
Show answer
A reboot keeps the instance on the same host, so the same physical disk and its contents remain. A stop releases the host, and the next start places the instance on a host with a new, blank, unformatted disk. You must format and mount it again, ideally with a boot-time script.