Yesterday I got to experience the joy of migrating an ec2 image from the us-east region to the us-west region on ec2. The best way to do this was to migrate the images through S3. You'll find some guides about using rsync and copying everything over through ssh, but I think those were written before AWS introduced ec2-bundle-vol and ec2-migrate-image.
Here are the steps we'll go through to migrate the image:
You'll need a running instance of your AMI to do this, so launch one if you do not have one up. The next thing to check is to make sure the ec2 command line tools are installed on your instance (they should be there by default). Try the command,
to be sure.
You'll also need the private key and certificate files for your AWS account on the server so that you can issue admin commands using the ec2 command line tools. These have to be regenerated each time you want to download them, so be sure to save them the first time you generate them. They can be found by going to My Account --> Security Credentials and clicking the X.509 Certificates tab under the Access Credentials heading.
Go ahead and upload these to your running instance:
Cool. Now that everything is prepared for the migration, let's create and attach a new volume to hold our bundled volume. Go ahead and create an empty volume and be sure to specify the same availability zone as the one in which your instance is running,
The max size of the bundle will be 10GiB so just be sure that you leave enough space for the bundled volume.
Next attach it to the running instance of the image,
Now we need to determine where the newly attached image was added. The comment in red tells us that our linux kernel may rename our device so it won't be at /dev/sdg necessarily. SSH into the instance and type the command,
Ok, so it was attached then at /dev/xdvf. Let's mount the new volume:
Perfect. We've mounted a new partition to store our bundled volume.
Before bundling the volume, check on the architecture as we'll need to provide this to the bundle-vol command.
Ok, now we just need to issue the ec2-bundle-vol command, (the -u option is your amazon aws account number)
If the default architecture value is correct, go ahead and hit return. You'll see output about the initialization of the bundling process which will take quite awhile to complete.
The next step is to transfer the bundle to S3 so that it can be migrated. In this step you'll need your aws access key and secret which can be found under Account --> Security Credentials. By default, the ec2-bundle-vol command creates a manifest file describing the image named image.manifest.xml in /mnt/backup. We'll need this filename for the next command,
All of the parts that were just created by bundling the volume will be uploaded to S3. In the meantime, figure out the region location you'd like to transfer the image to,
In this tutorial, we'll use us-west-1.
Now that the bundle has been uploaded to S3 in your source region, ensure that you have a bucket in S3 in your destination region to receive the image. I'll call mine my-us-norcal-bucket. Now, all we need to do is migrate the image from the source bucket to the destination bucket,
Finally we just need to register the image:
That's it. That's all.