Dowd and Associates

HowTo: Move an EC2 Instance Store AMI From One Region to Another

Moving an EC2 Instance Store AMI from one region to another is fairly straightforward and much easier than an EBS backed AMI.

To do this, we will need the following:

First we need to create a bucket in region we want to migrate to. In this article we’ll migrate to us-west-2.

This can be done with the aws cli tool like so:

Console - user@hostname ~ $
1
aws s3 mb s3://your-bucket-in-us-west-2 --region us-west-2

Or with s3cmd:

Console - user@hostname ~ $
1
s3cmd --bucket-location=us-west-2 mb s3://your-bucket-in-us-west-2

Or with s3curl:

Console - user@hostname ~ $
1
2
3
4
s3curl.pl \
--id friendly_id \
--createBucket us-west-2 -- \
https://your-bucket-in-us-west-2.s3.amazonaws.com

Or this can be done in the S3 Management Console:

  • Click “Create Bucket” on the top of the left hand column
  • Choose your bucket name
  • Select “Oregon” from the Region dropdown

Now that we have bucket, we can migrate the image. We’ll set --owner-akid to your AWS Access Key ID and --owner-sak to your AWS Secret Key. The migration tool is picky about the destination bucket, you can only put it in the root level, however we can add a key prefix (move it to a subdirectory) after the migration.

Console - user@hostname ~ $
1
2
3
4
5
6
7
8
9
ec2-migrate-image \
--owner-akid C99F5C7EE00F1EXAMPLE \
--owner-sak a63xWEj9ZFbigxqA7wI3Nuwj3mte3RDBdEXAMPLE \
--bucket your_bucket/key_prefix \
--destination-bucket your-bucket-in-us-west-2 \
--manifest image.manifest.xml \
--location us-west-2 \
--kernel aki-c2e26ff2 \
--region us-west-2

Once the migration is done, we can move it to a new “directory”. We can use the S3 Management Console to create a new directory and drag and drop the image files into said new directory. Another option is to use the aws command.

Console - user@hostname ~ $
1
2
3
4
5
6
7
8
aws s3 mv \
s3://your-bucket-in-us-west-2/ \
s3://your-bucket-in-us-west-2/key_prefix \
--recursive \
--region=us-west-2 \
--exclude "*" \
--include "*image.part.*" \
--include "*image.manifest.xml"

Or with s3cmd

Console - user@hostname ~ $
1
2
3
4
5
6
7
8
s3cmd \
--recursive \
--exclude="*" \
--include="image.manifest.xml" \
--include="image.part.*" \
mv \
s3://your-bucket-in-us-west-2/ \
s3://your-bucket-in-us-west-2/key_prefix

Finally we register new image

Console - user@hostname ~ $
1
2
3
4
ec2-register \
--region us-west-2 \
--kernel aki-c2e26ff2 \
your-bucket-in-us-west-2/key_prefix/image.manifest.xml

And now we’re ready to run our AMI in the new region.

Comments