Copying an Existing EC2 Instance to Another Region

Copying EC2 instances from one region to another is one way to increase resilience in case of a resource failure. In this guide, we'll walk through how to copy an EC2 instance from one region to another.

Patrick Londa
Author
Sep 27, 2022
 • 
5
 min read
Share this post

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.

aws logo
Blink Automation: Copy an EC2 Instance to Another Region
Blink + AWS
Get Started

How To Copy an EC2 Instance Across Regions

Before we get into the specific steps, you should review the following considerations:

  • Identity access management (IAM) policies can be used for permissions to copy AMIs
  • Some attached elements such as launch permissions, user-defined tags, or Amazon S3 bucket permissions cannot be copied from source to target instance
  • AWS Marketplace AMI instances cannot be copied across regions

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.

Creating an AMI of Your Existing EC2 Instance

You can create an AMI using either the console or the AWS CLI:

Using the EC2 Console

  1. In the Console, search for and navigate to the EC2 section.
  2. You can see a list of all the instances you have running, with details like instance type, instance ID, region, and more.
  3. Right click on the instance you want to use, and select Image and Templates, then Create Image.
  4. On the Create Image page, you can provide a name and description for your image, specify the size, tags, and whether the instance should be rebooted to create a more consistent image. Rebooting is the default option.
  5. Once all the settings look right, click the Create Image button.
  6. To view your new AMI, go to the left hand navigation and under Images, select AMIs.
  7. The Status of your image may show as Pending. If you wait a couple of minutes, it should change to Available and you’re ready to use your AMI for copying to another region.

Using 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:

aws ec2 create-image \
    --instance-id i-0b09a25c58929de26 \
    --name "My server" \
    --no-reboot

As an output, you’ll see the ID for your new AMI:

{
    "ImageId": "ami-01d7dcccb80665a0f"
}

In this next step, you can use this AMI ID to create your copied instance.

Copying the AMI to a Target Region

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.

Using the EC2 Console

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:

  • AMI copy name
  • AMI copy description
  • Destination region
  • Encrypt elastic block store (EBS) snapshots of AMI copy
  • Key management service (KMS) key

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 ActionsLaunch (old console).

Using the AWS CLI

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:

  • [--region <value>] 
  • --source-region <value>
  • --source-image-id <value>

In this example, an AMI from region us-west-2 is being copied to region us-east-1:

aws ec2 copy-image \
    --region us-east-1 \
    --name ami-name \
    --source-region us-west-2 \
    --source-image-id ami-066877671789bd71b \
    --description "This is my copied image."

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:

  • [--encrypted | --no-encrypted]
  • [--kms-key-id <value>]

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:

aws ec2 run-instances \
    --image-id ami-0abcdef1234567890 \
    --instance-type t2.micro \
    --key-name MyKeyPair

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.

Automating Common EC2 Tasks with Blink

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.

Automate your security operations everywhere.

Blink is secure, decentralized, and cloud-native. 
Get modern cloud and security operations today.

Get a Demo