EBS Operations: Volume Migration

Migrating an Amazon Elastic Block Store (EBS) volume from one Availability Zone (AZ) to another or to a different region can be accomplished through a series of steps, primarily involving the creation of EBS snapshots.

Migrate EBS Volume to a Different AZ in the Same Region

💡
To run the EC2 instance with the EBS volume attached follow this guide: How to launch a single EC2 instance via AWS CLI
  1. Create a Snapshot of the EBS Volume:

    • Identify the EBS volume ID that you want to migrate.
    aws ec2 describe-volumes --region us-east-1 --output table

  • Create a snapshot of the volume.
    aws ec2 create-snapshot --volume-id vol-05b25ed60988cf1da --description "Snapshot for AZ migration" --region us-east-1

  1. To get the ID of the newly created Snapshot in a specific region use the following command:

     aws ec2 describe-snapshots --region us-east-1 --owner-ids self --output table
    

  2. Create a New EBS Volume from the Snapshot in the Target AZ:

     aws ec2 create-volume --snapshot-id snap-068b9e5f8b05d011f --availability-zone us-east-1c --region us-east-1
    

  3. Attach the New EBS Volume to an EC2 Instance in the Target AZ:

    • First, ensure the original volume is detached if you're planning to attach the new volume to the same instance.
    aws ec2 attach-volume --volume-id vol-01102f9382dc6e3ca --instance-id i-0e6bd11c880ac0782 --device /dev/sdf

💡
When you attach a volume to an Amazon Linux 2 instance (or any other Nitro-based instances), even if you specify the device name as /dev/sdf, for instance, within the OS, it'll be recognized as a different NVMe name, like /dev/nvme1n1

  1. Clean Up: (Optional but recommended)

    • Delete the snapshot if it's no longer needed.
    aws ec2 delete-snapshot --snapshot-id SNAPSHOT-ID --region SOURCE-REGION

Migrate EBS Volume to a Different Region

  1. Create a Snapshot of the EBS Volume:

    • Follow the same steps mentioned above to create a snapshot of your EBS volume.

  2. Copy the Snapshot to the Target Region (from us-east-1 to eu-west-1):

     aws ec2 copy-snapshot --source-region us-east-1 --source-snapshot-id snap-05f638c55f3bfc119 --destination-region eu-west-1 --description "Snapshot for region migration"
    

  3. Create a New EBS Volume from the Copied Snapshot in the Target Region:

     aws ec2 create-volume --snapshot-id COPIED-SNAPSHOT-ID --availability-zone TARGET-AZ --region TARGET-REGION
    
  4. Attach the New EBS Volume to an EC2 Instance in the Target Region:

    • Ensure the original volume is detached if you're planning to attach the new volume to the same instance.
    aws ec2 attach-volume --volume-id NEW-VOLUME-ID --instance-id INSTANCE-ID --device /dev/sdf --region TARGET-REGION
  1. Clean Up:

    • Delete the original and copied snapshots if they're no longer needed.
    aws ec2 delete-snapshot --snapshot-id SNAPSHOT-ID --region SOURCE-REGION
    aws ec2 delete-snapshot --snapshot-id COPIED-SNAPSHOT-ID --region TARGET-REGION

Remember:

  • Ensure that you have the necessary permissions to perform these operations.

  • Depending on the size of your EBS volume, creating and copying snapshots can take some time.

  • Ensure you handle any application downtime, data integrity, or consistency mechanisms appropriately when detaching/attaching volumes.