I have a setup in AWS Ireland region, now I want that AMI in my China. Does anybody know what is the best practice to achieve the task? Any help will be appreciated.
Thanks in advance.
AMI copy is currently not supported for China region. The idea is to create a dump file of the volume using 'dd', copy the file to a temporary instance in China Region. Once copied, use dd again to dump the contents of the file to an EBS volume.
You can copy an Amazon Machine Image (AMI) into or to another AWS Region using the AWS Management Console, the AWS Command Line Interface, or SDKs, or the Amazon EC2 API, all of which support the CopyImage action. You can copy Amazon EBS-based AMIs and Instance Store AMIs.
It's not possible to move an existing instance to another subnet, Availability Zone, or VPC. Instead, you can manually migrate the instance by creating a new Amazon Machine Image (AMI) from the source instance. Then, launch a new instance using the new AMI in the desired subnet, Availability Zone, or VPC.
only be used to launch EC2 instances in the same AWS region as the AMI is stored. (An AMI is tied to the region where its files are located within Amazon S3) only be used to launch EC2 instances in the same AWS availability zone as the AMI is stored.
AMI copy is currently not supported for China region.
According to AWS: Transfer or copy AMI from US to China (Beijing)
The idea is to create a dump file of the volume using 'dd', copy the file to a temporary instance in China Region. Once copied, use dd again to dump the contents of the file to an EBS volume. Then create a snapshot of the EBS volume which contains the data and create an AMI out of it.
You may refer an over view of the process below:
- Launch a linux instance in the AWS Region then use "dd” command to save the instance’s whole root volume as a file to a secondary EBS volume.
mkfs.ext4 /dev/xvdf
mount /dev/xvdf /mnt
dd if=/dev/xvda of=root.img bs=1M
- Copy the file to an instance in cn-north-1 region.
scp -i key.pem root.img ec2-user@<ip_address>:/tmp
- In that cn-north-1 region’s instance, use ‘dd’ command to write that file to an EBS volume
dd if=/tmp/root.img of=/dev/xvdf bs=1M oflag=direct
- Delete the keypair on the volume, where
{cloud username}
is 'ubuntu' for ubuntu, 'ec2-user' for Amazon Linux, 'admin' for Debian, 'core' for CoreOS/Container Linux
mkdir -p /tmp/volume
partprobe
mount /dev/xvdf1 /tmp/volume
rm /tmp/volume/root/.ssh/authorized_keys
rm /tmp/volume/home/{cloud username}/.ssh/authorized_keys
umount /tmp/volume
Create a snapshot of the volume, refer here.
Create an AMI from the snapshot, refer here.
Finally, use that AMI to launch an instance, which is the same as the instance running in the original AWS region.
NB=Please note that in some cases, you might need to update /etc/fstab, grub configuration files etc. with the label of the new volume.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With