Unfortunately Amazon doesn’t have an easy or native way to copy or move or launch an AWS AMI from one region to another. There are a number of posts on the Internet about how to do this with a Linux AMI, but I haven’t been able to find clear instructions on how to do this for a Windows AMI. So, here we go…
The basic steps involve starting a temporary Windows instance in each of the two regions, say us-east-1 and us-west-1; attaching the EBS boot volume to the server in the “source” region; making an image or zip file of the volume; copying the volume to the temporary server in the “destination” region; extracting the file to a new volume; finally, attaching that volume to a server.
Notes:
- This will take a while (several hours), particularly if your AMI is large.
- Clean up the boot volume of the image you want to copy to another region by deleting any unnecessary files, such as temporary files, etc. as it will reduce the overall time this process takes.
- Launch a temporary Windows instance in the “source” region and another one in the “target” region. (You may not have to launch temporary servers if you have one available in each that can handle the load of compressing a large volume which can be quite CPU intensive. Additionally you need to have enough available disk space for the compressed volume to be stored temporarily.)
- Determine the snapshot for the boot volume you want to migrate (you must own the AMI) using the command ec2-describe-images.
- Create a new EBS volume from that snapshot in the same zone as your origin server. This can be done many ways, but here’s how to do it from the command line using the AWS tools:
ec2-create-volume --snapshot <snap ID> -z us-east-1c - Attach that volume to your temporary server instance as, say, “xvdg”:
ec2-attach-volume <volumeID> –i <instanceId> –d xvdg
NOTE: You will be able to browse the contents of the volume in Windows Explorer. - Connect to your temporary source server with RDP.
- Zip the entire contents of the newly attached volume. NOTE: I used 7zip and sent the zipped file to another volume on the temporary source server in 1GB chunks (this makes it easier and quicker to transfer to the destination server; in particular you can begin copying the chunks soon as each is finished rather than waiting for one large file.)
- Copy that zipped file (or files) to your instance in the “target” region. This could be done by a variety of methods. I chose to copy my 1GB chunks to an Amazon S3 bucket, then I could easily download those onto the destination server.
In the target region:
- Create an EBS volume of appropriate size (30GB for Windows 2008 by default) and attach it to your temporary destination server.
- Unzip the file to the new volume. Again, I used 7zip.
- Detach the volume.
Now, for the Windows specific stuff….
- Launch a basic Windows 2008 instance of the right architecture (32 or 64 bit).
- Soon as the instance is “running” (see Pinging Amazon EC2 Instances to determine exactly when your instance is available) stop it and wait for its state to become “stopped”.
- Once it stops, detach its “/dev/sda1” volume and delete it using ec2 commands:
ec2-detach-volume <the_volumeID_of_sda1> –i <new_windows_instance>
ec2-delete-volume <the_volumeID_of_sda1> - Now attach the new volume (from steps 8-10) to the stopped Windows instance as ‘/dev/sda1’:
ec2-attach-volume <vol_id> –i <windows_instance_id> –d /dev/sda1 - Start the instance to make sure it boots, and connect to it with RDP.
- When you’re satisfied that it boots and is setup the way you desire, stop the instance using ec2stop -i <instanceID>.
- Finally, create an AMI from that server by running ec2-create-image -i <instanceID>.
That’s it. Now you have an AMI in a different AWS zone that is a copy of one from your initial zone.