Moving an EC2 EBS AMI from one region to another has become easy. Here we’ll show how to do it.
CopyImage
The straightforward way to copy an AMI is to use the CopyImage
action. Just tell it what the AMI id is and what region it is in.
Note This will not work with an AMI that uses encrypted snapshots.
In this example we’ll copy ami-12345678
from us-east-1 to us-west-2.
Example API Request
1
2
3
4
5 https://ec2.us-west-2.amazonaws.com
?Action=CopyImage
&SourceRegion=us-east-1
&SourceImageId=ami-12345678
&*AUTHPARAMS*
Console - user@hostname ~ $
1
2
3
4 aws --region us-west-2 ec2 \
copy-image \
--source-region "us-east-1" \
--source-image-id "ami-12345678"
Output
1
2
3 {
"ImageId" : "ami-abcdef01"
}
Here we see that it will be ami-abcdef01
on us-west-2
CopySnapshot / RegisterImage
Another way to accomplish this is to copy the snapshot(s) that back the AMI and register it on the other region.
CopySnapshot
We’ll use the CopySnapshot
action to copy snap-12345678
from us-east-1 to us-west-2.
Example API Request
1
2
3
4
5
6
7 https://ec2.us-west-2.amazonaws.com
?Action=CopySnapshot
&SourceRegion=us-east-1
&SourceSnapshotId=snap-12345678
&DestinationRegion=us-west-2
&Description=Example&20Description
&*AUTHPARAMS*
Console - user@hostname ~ $
1
2
3
4
5
6 aws --region us-west-2 ec2 \
copy-snapshot \
--source-region "us-east-1" \
--source-snapshot-id "snap-12345678" \
--destination-region "us-west-2" \
--description "Example Description"
Output
1
2
3 {
"SnapshotId" : "snap-abcdef01"
}
RegisterImage
Once the snapshot(s) are copied over we can use the RegisterImage
action to create the AMI. Remember to use the snapshot id of the copy, snap-abcdef01
in this case.
Example API Request
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 https://ec2.us-west-2.amazonaws.com/
?Action=RegisterImage
&Name=Example_Image_Name
&Description=Example%20Image%20Description
&Architecture=x86_64
&KernelId=aki-e68f11d6
&RootDeviceName=/dev/sda
&BlockDeviceMapping.1.DeviceName=/dev/sda1
&BlockDeviceMapping.1.SnapshotId=snap-abcdef01
&BlockDeviceMapping.2.DeviceName=/dev/sdb
&BlockDeviceMapping.2.VirtualName=ephemeral0
&BlockDeviceMapping.3.DeviceName=/dev/sdc
&BlockDeviceMapping.3.VirtualName=ephemeral1
&BlockDeviceMapping.4.DeviceName=/dev/sdd
&BlockDeviceMapping.4.VirtualName=ephemeral2
&BlockDeviceMapping.5.DeviceName=/dev/sde
&BlockDeviceMapping.5.VirtualName=ephemeral3
&*AUTHPARAMS*
Console - user@hostname ~ $
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 aws --region= us-west-2 ec2 \
register-image \
--name "Example_Image_Name" \
--description "Example Image Description" \
--architecture x86_64 \
--kernel-id aki-e68f11d6 \
--root-device-name "/dev/sda" \
--block-device-mappings "[
{
\" DeviceName \" : \" /dev/sda1 \" ,
\" Ebs \" : {
\" SnapshotId \" : \" snap-abcdef01 \"
}
},
{
\" DeviceName \" : \" /dev/sdb \" ,
\" VirtualName \" : \" ephemeral0 \"
},
{
\" DeviceName \" : \" /dev/sdc \" ,
\" VirtualName \" : \" ephemeral1 \"
},
{
\" DeviceName \" : \" /dev/sdd \" ,
\" VirtualName \" : \" ephemeral2 \"
},
{
\" DeviceName \" : \" /dev/sde \" ,
\" VirtualName \" : \" ephemeral3 \"
}
]"
Output
1
2
3 {
"ImageId" : "ami-a1b2c3d4"
}
And now we have our image set up on us-west-2.