AWS

How to Migrate EC2 Instance From One AWS Region to Another Region

Most AWS services are region-specific; these services are deployed into a specific AWS region. AWS recommends deploying services into the regions closer to the customers accessing these services. AWS EC2 is also region-specific, and EC2 instances can be deployed to specific AWS regions. EC2 instances on AWS can be migrated from one AWS region to another AWS region. Migration of an EC2 instance can be performed by following the given steps.

  1. Create a new AMI from the EC2 instance
  2. Copy the AMI to the destination region
  3. Launch the EC2 instance into the destination region
  4. Terminate the old EC2 instance

In this guide, we will discuss how to migrate an EC2 instance from one AWS region to another region.

Create a new AMI from the EC2 instance

The first step to migrating the EC2 instance from the source AWS region to the destination AWS region is to create an AMI of the EC2 instance. AMI (Amazon Machine Image) is an operating system like Windows or Linux for an EC2 instance, and it contains all the information and permissions to launch an image. You can either use AMI from the AWS marketplace or even develop your own.

So to create an AMI from an instance, simply select the instance you want to migrate, click on “actions,” and there, under the “image and templates” tab, you will see the option to “create image.” The instance can either be stopped or in running condition while creating an image, but it is recommended to stop the instance from getting a stable AMI.

In the create image section, first, you need to provide the image name for your new AMI; you can optionally add a description about your AMI.

Then you can attach more EBS volumes and the existing root volume if you want. For this demo, we will not attach any additional volume.

For tags, select the “Tag image and snapshot together” option to add the same tags to the newly created AMI as the original EC2 instance has. Also, you can add custom tags for your AMI by clicking on the Add Tag button.

After adding tags, go to the end of the page and click on the create image button to create the image.

Once our AMI has been created, open the AMI section from the left menu in the EC2 console, and you will find it there.

So our AMI image has been successfully created.

Copy the AMI to the destination region

Now what we have to do is to copy our instance AMI from the previous region to the new region where we want to migrate the instance. To do this, simply select the image in the AMI section, click on the “Actions” button and click on “Copy AMI.”


Provide the destination region for your AMI where you want your AMI to be migrated, and simply click on the copy AMI button in the bottom right corner.


The copying process from one region to another may take some time, depending on the data’s amount in the root volume. After completion, you can go to the destination region, and there you will find the copied instance image in the AMI section.


So our AMI is moved from one AWS region to the other. You can also copy your AMI to multiple regions if you require.

Launch the EC2 instance into the destination region

Finally, now we can launch our EC2 instance in the new region using the AMI from our older instance in the previous region. You just need to select your image and click on “Launch instance from image.


To configure the instance, you simply have to follow the usual steps, except you will not be required to select the AMI.


So we have successfully migrated our EC2 instance from one region to the other.

Terminate the old EC2 instance

The last step, which is very important to mention, is that after launching your instance in the new region, you have to stop or terminate the original instance if you don’t require it anymore; otherwise, it will cost you extra AWS billing.

For this, select the instance and click on the Instance state button. A list will appear with multiple options. Click on the Terminate instance to terminate the EC2 instance.


So we have seen how to migrate an EC2 instance using the AWS management console.

Migrate EC2 Instance Using CLI

So now, in this section, we are going to use the AWS command-line interface (CLI) to migrate our instance between two regions.

So first, we need to create AMI from our instance using the following command.

$: aws ec2 create-image --instance-id <ID> --name "Image Name" --description "description" --no-reboot


Now we have to copy the AMI from one region to the other. The command to perform this action is as follows.

$: aws ec2 copy-image --region <Destination Region> --name <Image Name> --source-region <Present AMI Region> --source-image-id <AMI ID> --description "<Description>"

Now we will launch the EC2 instance in the designation region using this copied AMI.

$: aws ec2 run-instances --image-id <AMI ID> --instance-type <Type>


The command will generate the following detailed output about the created instance.


So our instance is successfully migrated using the AWS command-line interface.

Conclusion:

As the concept of cloud infrastructure is increasing and AWS is expanding its services and availability zones and regions at a high rate, a user may require to shift or migrate his old services and resources to a region in order to get the least latency and higher data transfer rate that is why AWS provides the ability to migrate your running services like EC2 instances or storage volumes from one region to another. This can also be helpful if you want to deploy more resources for your application or system but do not want to design and build everything from scratch.

About the author

Zain Abideen

A DevOps Engineer with expertise in provisioning and managing servers on AWS and Software delivery lifecycle (SDLC) automation. I'm from Gujranwala, Pakistan and currently working as a DevOps engineer.