Copying an Existing EC2 Instance to Another Region
Learn how to copy an EC2 instance to another region to increase resilience. Follow this step-by-step guide for seamless EC2 instance migration.
Learn how to copy an EC2 instance to another region to increase resilience. Follow this step-by-step guide for seamless EC2 instance migration.
If your primary EC2 instances in a region go down for any reason, what is your failover plan? In other words, how can you seamlessly switch to backup instances?
In the AWS Well-Architected framework, a best practice under the Reliability pillar is to have healthy resources available in other locations so that if a resource failure occurs, you can continue to serve requests.
Copying EC2 instances from one region to another is a way of ensuring that you have reliable backup systems in place, ready to be used in a disaster or regional disruption.
In this guide, we’ll walk through how you can copy an existing EC2 instance to another region to boost your system reliability.
Before we get into the specific steps, you should review the following considerations:
Fundamentally, copying an EC2 instance to another takes a few steps. First, you need to create an Amazon Machine Image (AMI) of the instance you want to copy. Then, you need to copy that AMI to the target region. Last, you can use the relocated AMI to launch your new instance in your desired region.
You can create an AMI using either the console or the AWS CLI:
You can create an Amazon EBS-backed AMI using the AWS CLI. All you need is an instance to base the image off of that is either running or stopped. If no existing instance fits your needs, you can customize an existing one or create a new one.
Creating an AMI will reboot the instance so the image is consistent with the data at rest. If you don’t want to stop the instance, you can use the “--no-reboot” parameter to keep the instance running and risk file integrity issues.
To create an AMI, you can use the “create-image” command and specify your desired details, such as referencing a “--instance-id” value.
Here’s an example of doing just that:
As an output, you’ll see the ID for your new AMI:
In this next step, you can use this AMI ID to create your copied instance.
Now that we have the AMI we want to copy to another region, let’s walk through the steps for copying it over to another region.
1. Open Amazon EC2 console, and select the region that contains the AMI you want to use.
2. In the left-hand navigation, select AMIs under Images to display all AMIs in your selected region.
3. For the AMI you want to copy, right click to show Actions, and then select Copy AMI.
4. On Copy AMI, specify each of the following parameters:
5. When everything looks right, select Copy AMI.*
(*Once copied, your newly created instance is designated as Pending. You should be able to use your newly copied instance once the status changes to Available.)
6. To launch an instance from the new AMI, follow steps 1-3 again and select the new AMI. You can choose Launch instance from AMI (new console) or Actions → Launch (old console).
You can use the “copy-image” command to copy an AMI to another region by specifying the target region, the AMI ID, and the source region.
These are the key parameters to use:
In this example, an AMI from region us-west-2 is being copied to region us-east-1:
Similar to how we created the AMI in the first section, the output will contain the new AMI ID. If you need to encrypt a target snapshot during copying, you can add these parameters to the command:
You can then use the new AMI ID in the target region to launch a new instance.
With the AWS CLI, you can use the run-instances command. This example launches a new instance into a default subnet based on a AMI ID:
By working through these steps, with either the console or the CLI, you now know how to create an AMI of an instance and copy it to another region.
The steps for copying EC2 instances to another region are not that difficult, but there are several manual steps. If you encounter a resource failure, you aren’t going to want to look up and run these commands one by one.
Automation can help speed up your recovery and make copying an instance to another region as simple as a couple clicks.
With Blink, you can use no-code steps to automate common EC2 management tasks. By saving time and taking actions based on first principles, you can scale your efforts and achieve new levels of resilience.
Get started with Blink today and see how easy it is to automate your most common EC2 tasks.
Blink is secure, decentralized, and cloud-native. Get modern cloud and security operations today.