An EBS volume is a network disk. It lives in one availability zone and attaches to one instance in that zone. The root volume of every instance is one; this lesson adds a second, for data.
| Type | Medium | For |
|---|---|---|
gp3 | SSD | almost everything: boot disks, web servers, small databases |
io2 | SSD | busy databases that need guaranteed speed (IOPS) |
st1 | HDD | large files read in sequence: logs, data processing |
sc1 | HDD | the cheapest, for data read rarely |
Creating and attaching
The volume must be in the instance's zone. describe-instances shows it under Placement.AvailabilityZone.
VOL=$(aws ec2 create-volume --availability-zone us-east-1a --size 8 --volume-type gp3 --tag-specifications 'ResourceType=volume,Tags=[{Key=Name,Value=market-data}]' --query VolumeId --output text)--size is in GiB. The volume is creating for a few seconds, then available; attaching it before that fails with IncorrectState, so give it a moment.
aws ec2 attach-volume --volume-id $VOL --instance-id $ID --device /dev/sdf--device is the name the instance will see it under. A volume in another zone fails with InvalidVolume.ZoneMismatch.
aws ec2 describe-volumes --volume-ids $VOL --query "Volumes[0].[State,Attachments[0].State]" --output textin-use and attached mean the instance has it. It is empty and unformatted: the next lesson makes it usable. In a new terminal, find the volume again by its Name:
VOL=$(aws ec2 describe-volumes --filters Name=tag:Name,Values=market-data --query "Volumes[0].VolumeId" --output text)A volume is billed for its full size every month it exists, attached or not, empty or full.