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:
- ec2-ami-tools
- AWS Access Key ID
- AWS Secret Key
- An S3 Client (such as the AWS CLI, s3cmd, s3curl, or the S3 Management Console)
- The kernel image to use in the new region (which will probably be PV Grub, do make sure to pick the same version, architecture and partition type)
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.