57

Any easy way to move and custom AMI image between regions? (tokyo -> singapore)

I know you can mess up with API and S3 to get it done, but there there any easier way to do it?

c2h2
  • 11,911
  • 13
  • 48
  • 60

11 Answers11

92

As of December, 2012, Amazon now supports migrating an AMI to another region through the UI tool (Amazon Management Console). See their documentation here

So, how I've done it is..

  1. From the AMI find out the Snapshot-ID and how it is attached (e.g. /dev/sda1)
  2. Select the Snapshot, click "Copy", set Destination region and make the copy (takes a while!)
  3. Select the new Snapshot, click "Create Image"

        Architecture: (choose 32 or 64 bit)

        Name/Description: (give it one)

        Kernel ID: when migrating a Linux AMI, if you choose "default" it may fail. What worked for me was to go to the Amazon Kernels listing here to find the kernels Amazon supports, then specify it when creating the image)

        Root Device Name: /dev/sda1

        Click "Yes, Create"

  4.Launch an instance from the new AMI and test that you can connect.

dmohr
  • 2,699
  • 1
  • 22
  • 22
  • Finally got this working. The root device name may not always be sda1. If you're using a hd00 kernel which uses /dev/sda as the root disk (i.e: no partitions) that'll need to be /dev/sda on the new AMI also. – Sirex Jan 18 '13 at 01:24
  • 3
    Also won't work for Windows instances - the Create Image step won't allow you to create a Windows AMI of your own - it ends up with a type of Other Linux, which fails to boot properly. – Chris Moschini Mar 06 '13 at 10:27
  • 2
    @Chris, for Windows, you are correct - however there is a way to do it, see my 2nd post as "tibcoeducation" in this thread here – dmohr Mar 09 '13 at 01:54
7

The following assumes your AWS Console utilities are installed in /opt/aws/bin/, JAVA_HOME=/usr and you are running i386 architecture, otherwise replace with x86_64.

1) Run a live snapshot, where you believe your image can fit in 1.5GB and you have that to spare in /mnt (check running df)

/opt/aws/bin/ec2-bundle-vol -d /mnt -k /home/ec2-user/.ec2/pk-XXX.pem -c /home/ec2-user/.ec2/cert-XXX.pem -u 123456789 -r i386 -s 1500

2) Upload to current region's S3 bucket

/opt/aws/bin/ec2-upload-bundle -b S3_BUCKET -m /mnt/image.manifest.xml -a abcxyz -s SUPERSECRET

3) Transfer the image to EU S3 bucket

/opt/aws/bin/ec2-migrate-image -K /home/ec2-user/.ec2/pk-XXX.pem -C /home/ec2-user/.ec2/cert-XXX.pem -o abcxyz -w SUPERSECRET --bucket S3_BUCKET_US --destination-bucket S3_BUCKET_EU --manifest image.manifest.xml --location EU

4) Register your AMI so you can fire up the instance in Ireland

/opt/aws/bin/ec2-register –K /home/ec2-user/.ec2/pk-XXX.pem –C /home/ec2-user/.ec2/cert-XXX.pem http://s3.amazonaws.com:80/S3_BUCKET/image.manifest.xml --region eu-west-1 -name DEVICENAME -a i386 --kernel aki-xxx

7

You can do it using Eric's post: http://alestic.com/2010/10/ec2-ami-copy

Rodney Quillo
  • 3,312
  • 1
  • 18
  • 9
6

There are API tools for this. http://docs.amazonwebservices.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-MigrateImage.html

waxical
  • 3,826
  • 8
  • 45
  • 69
  • Remember this one is only for instance-based EC2 AMI (non-EBS), for EBS AMI see answers from micred and rynop – number5 Jan 03 '13 at 22:04
4

I think that is now outdated by ec2-bundle-vol and ec2-migrate-image, BTW you can also take a look at this Perl script by Lincoln D. Stein: http://search.cpan.org/~lds/VM-EC2/bin/migrate-ebs-image.pl

Usage:

$ migrate-ebs-image.pl --from us-east-1 --to ap-southeast-1 ami-123456

micred
  • 1,482
  • 1
  • 19
  • 19
4

Amazon have just announced support for this functionality in this blog post. Note that the answer from dmohr relates to copying EBSs, not AMIs.

In case the blog post is unavailable, quoting the relevant parts:

To use AMI Copy, simply select the AMI to be copied from within the AWS Management Console, choose the destination region, and start the copy. AMI Copy can also be accessed via the EC2 Command Line Interface or EC2 API as described in the EC2 User’s Guide. Once the copy is complete, the new AMI can be used to launch new EC2 instances in the destination region.

Frodo Baggins
  • 8,290
  • 6
  • 45
  • 55
  • You can copy AMIs with dmohr instructions. if the AMI has multiple volumes/snapshots then it might be a bit more complicated. But once you move the snapshots, you can create an Image (or AMI) and then start the instance on the other region – Gianfranco P. Jan 06 '14 at 11:54
3

AWS now supports the copy of an EBS snapshot to another region via UI/CLI/API. You can copy the snapshot and then make an AMI from it. Direct AMI copy is coming - from AWS:

"We also plan to launch Amazon Machine Image (AMI) Copy as a follow-up to this feature, which will enable you to copy both public and custom-created AMIs across regions.

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-copy-snapshot.html?ref_=pe_2170_27415460

rynop
  • 50,086
  • 26
  • 101
  • 112
1

As of 2017, it's pretty simple.. just follow the screenshots:

enter image description here

enter image description here

enter image description here

enter image description here

GorvGoyl
  • 42,508
  • 29
  • 229
  • 225
1

Ylastic allows you to move EBS backed linux images between regions.

Its $25 or $50 per month but it looks like you can evaluate it for a week.

Geoff Appleford
  • 18,538
  • 4
  • 62
  • 85
1

I just did this using a script on CloudyScripts, worked fantastically: https://cloudyscripts.com/tool/show/5 (and it's free).

James Yale
  • 111
  • 3
0

I'll add Scalr to the list of tools you can use (Disclaimer: I work there). Within Scalr, you can create your own AMI (we call them roles). Once your role is ready, you just have to choose where you want to deploy it (so in any regions).

Scalr is open-source released under the Apache 2 license: you can to download it and install it yourself. Otherwise, it is also available through a hosted version including support. Alternatives to Scalr includes RightScale and enStratus.

  • Can you actually use scalr to copy existing roles between regions? If so could you point me to some documentation that would help me? – Josh Stuart Mar 09 '13 at 22:22