Move an EBS volume between zones with a snapshot, and set out an AWS Backup plan
Task
Create a small Amazon EBS volume in one Availability Zone, take a snapshot of it, and create a new volume from that snapshot in a second zone, which is how EBS data moves between zones. Check which instance types have an instance store. Then create an AWS Backup vault and a backup plan that says how often to back up and how long to keep each backup, without assigning any resource to it. At the end you can show that a volume belongs to one zone, that a snapshot is the way across, and that a backup plan protects nothing until resources are assigned to it.
Steps
- Pick two Availability Zones and keep their names:
AZ1=$(aws ec2 describe-availability-zones --filters Name=zone-type,Values=availability-zone --query 'AvailabilityZones[0].ZoneName' --output text)
AZ2=$(aws ec2 describe-availability-zones --filters Name=zone-type,Values=availability-zone --query 'AvailabilityZones[1].ZoneName' --output text)
echo $AZ1 $AZ2
- See which instance types come with an instance store. This only reads:
aws ec2 describe-instance-types --instance-types t3.micro m5d.large --query 'InstanceTypes[].[InstanceType,InstanceStorageSupported]' --output text
t3.micro shows False: it has only network-attached EBS storage. m5d.large shows True: the d in its name marks local disks on the host, which are fast and included in the instance price, but whose data is lost when the instance stops or terminates. 3. Create a 1 GiB gp3 volume in the first zone and wait until it is available:
VOL_ID=$(aws ec2 create-volume --availability-zone $AZ1 --size 1 --volume-type gp3 --tag-specifications 'ResourceType=volume,Tags=[{Key=Name,Value=clf-lab19-vol}]' --query 'VolumeId' --output text)
aws ec2 wait volume-available --volume-ids $VOL_ID
aws ec2 describe-volumes --volume-ids $VOL_ID --query 'Volumes[0].[AvailabilityZone,Size,State]' --output text
It prints your first zone, 1 and available. This volume can attach only to an instance in that same zone. 4. Take a snapshot of the volume and wait for it to complete. An empty volume snapshots quickly, but it can still take a few minutes:
SNAP_ID=$(aws ec2 create-snapshot --volume-id $VOL_ID --description "clf-lab19 snapshot of an empty volume" --tag-specifications 'ResourceType=snapshot,Tags=[{Key=Name,Value=clf-lab19-snap}]' --query 'SnapshotId' --output text)
echo $SNAP_ID
aws ec2 wait snapshot-completed --snapshot-ids $SNAP_ID
The snapshot is private to your account; leave its permissions as they are. 5. Create a new volume from the snapshot in the second zone:
COPY_ID=$(aws ec2 create-volume --availability-zone $AZ2 --snapshot-id $SNAP_ID --volume-type gp3 --tag-specifications 'ResourceType=volume,Tags=[{Key=Name,Value=clf-lab19-vol-copy}]' --query 'VolumeId' --output text)
aws ec2 wait volume-available --volume-ids $COPY_ID
aws ec2 describe-volumes --volume-ids $VOL_ID $COPY_ID --query 'Volumes[].[Tags[0].Value,AvailabilityZone,SnapshotId]' --output table
The two volumes sit in different zones, and the copy records the snapshot it came from. A volume cannot move zones itself; the snapshot carried it. 6. Create a backup vault and a backup plan. The plan's one rule backs up daily at 05:00 UTC, moves each backup to cold storage after 30 days and deletes it after 120:
aws backup create-backup-vault --backup-vault-name clf-lab19-vault
cat > plan.json <<'EOF'
{
"BackupPlanName": "clf-lab19-plan",
"Rules": [
{
"RuleName": "daily-keep-120-days",
"TargetBackupVaultName": "clf-lab19-vault",
"ScheduleExpression": "cron(0 5 * * ? *)",
"Lifecycle": {"MoveToColdStorageAfterDays": 30, "DeleteAfterDays": 120}
}
]
}
EOF
PLAN_ID=$(aws backup create-backup-plan --backup-plan file://plan.json --query 'BackupPlanId' --output text)
echo $PLAN_ID
- Open the AWS Backup console and choose Backup plans, then
clf-lab19-plan. The Backup rules panel showsdaily-keep-120-days, and Resource assignments is empty. That is deliberate: a plan protects only the resources assigned to it, usually by tag, so this one will never take a backup. Do not assign the volumes to it; the clean-up deletes them the same day.
Verify
Run these read-only checks:
aws ec2 describe-volumes --filters Name=tag:Name,Values=clf-lab19-vol,clf-lab19-vol-copy --query 'length(Volumes)'
Expected output: 2.
aws ec2 describe-snapshots --owner-ids self --filters Name=tag:Name,Values=clf-lab19-snap --query 'Snapshots[0].State' --output text
Expected output: completed.
aws ec2 describe-volumes --filters Name=tag:Name,Values=clf-lab19-vol-copy --query "length(Volumes[?SnapshotId!=''])"
Expected output: 1, the copy made from a snapshot.
aws backup list-backup-plans --query "BackupPlansList[?BackupPlanName=='clf-lab19-plan'] | length(@)"
Expected output: 1.
aws backup describe-backup-vault --backup-vault-name clf-lab19-vault --query 'NumberOfRecoveryPoints'
Expected output: 0: the vault exists and holds no backups, because nothing is assigned to the plan.
Cost and clean-up
EBS volumes are charged for their size for as long as they exist, attached or not, and snapshots for the data they store; the AWS Free Tier may cover some of this. Two 1 GiB volumes kept for under an hour, and a snapshot of an empty volume, cost very little, but a forgotten volume is charged every month. The backup vault and an unassigned backup plan store nothing. See the Amazon EBS and AWS Backup pricing pages, or the AWS Pricing Calculator, for current rates.
Created by this lab: the EBS volumes clf-lab19-vol and clf-lab19-vol-copy; the EBS snapshot clf-lab19-snap; the backup plan clf-lab19-plan; the backup vault clf-lab19-vault; the working file plan.json in your CloudShell home directory.
- Look the resources up again by name, so the clean-up works even if CloudShell has restarted:
VOL_ID=$(aws ec2 describe-volumes --filters Name=tag:Name,Values=clf-lab19-vol --query 'Volumes[0].VolumeId' --output text)
COPY_ID=$(aws ec2 describe-volumes --filters Name=tag:Name,Values=clf-lab19-vol-copy --query 'Volumes[0].VolumeId' --output text)
SNAP_ID=$(aws ec2 describe-snapshots --owner-ids self --filters Name=tag:Name,Values=clf-lab19-snap --query 'Snapshots[0].SnapshotId' --output text)
PLAN_ID=$(aws backup list-backup-plans --query "BackupPlansList[?BackupPlanName=='clf-lab19-plan'].BackupPlanId" --output text)
echo $VOL_ID $COPY_ID $SNAP_ID $PLAN_ID
It should print four IDs. If one prints None or nothing, that resource is already gone: skip its delete below. 2. Delete both volumes and wait until they have gone:
aws ec2 delete-volume --volume-id $VOL_ID
aws ec2 delete-volume --volume-id $COPY_ID
aws ec2 wait volume-deleted --volume-ids $VOL_ID $COPY_ID
- Delete the snapshot:
aws ec2 delete-snapshot --snapshot-id $SNAP_ID
- Delete the backup plan, then the vault. A vault can be deleted only when it holds no recovery points, and this one holds none:
aws backup delete-backup-plan --backup-plan-id $PLAN_ID
aws backup delete-backup-vault --backup-vault-name clf-lab19-vault
- Remove the working file
plan.json:
rm -f plan.json
Check it is gone
aws ec2 describe-volumes --filters Name=tag:Name,Values=clf-lab19-vol,clf-lab19-vol-copy --query 'length(Volumes)'
Expected output: 0.
aws ec2 describe-snapshots --owner-ids self --filters Name=tag:Name,Values=clf-lab19-snap --query 'length(Snapshots)'
Expected output: 0.
aws backup list-backup-plans --query "BackupPlansList[?BackupPlanName=='clf-lab19-plan'] | length(@)"
Expected output: 0.
aws backup list-backup-vaults --query "BackupVaults[?BackupVaultName=='clf-lab19-vault'] | length(@)"
Expected output: 0.
Notes
The lab leaves Amazon EFS, Amazon FSx and AWS Storage Gateway to the lesson. An FSx file system is charged for its capacity from the moment it exists, a Storage Gateway needs a virtual machine on premises, and a shared file system only shows its value with several instances mounting it. What the lab does show is the lesson's central contrast for block storage: an EBS volume persists and lives in one zone, a snapshot is the way across zones, and instance store comes with certain instance types and is temporary. Cold storage in a backup rule applies only to resource types that support it; the AWS Backup documentation lists them.
This is an independent study companion for the AWS Certified Cloud Practitioner (CLF-C02) exam and is not produced by or endorsed by Amazon Web Services. AWS, Amazon Web Services and AWS Certified Cloud Practitioner are trademarks of Amazon.com, Inc. or its affiliates.
This is an independent study companion for AWS Certified Cloud Practitioner CLF-C02 and is not produced by or endorsed by CompTIA.