Blog Articles
Read MSP360’s latest news and expert articles about MSP business and technology
move ec2 to different region

How to Move Amazon EC2 Instance to a Different Availability Zone, Virtual Private Cloud or a Region (CLI Scripts Included)

How to Move Amazon EC2 Instance to a Different Availability Zone, Virtual Private Cloud or a Region (CLI Scripts Included)

Moving Amazon EC2 instance to another Availability Zone, VPC or AWS Region may result in a headache for administrators, who think that it is a must to stop the existing and brand a new instance each time. If it’s a production instance, the interruption disrupts the working process and leads to the significant money/time losses. So, do you really have to migrate all the data manually?

The answer is “no” if you know how to properly use AWS native tools.  In this article, we explain how to easily move working Amazon EC2 instance to a different Availability Zone, VPC or AWS Region.

Table of Contents

    Let’s get started from the step one.

    Step 1: Create an AMI

    • Under the EC2 section, choose Instances, right-click an instance you wish to migrate and choose  Image --> Create Image

    AWS: change Region, Availability Zone or VPC - Creating Amazon EC2 Instance image

    Here is an AWS CLI script:

    @echo off
    set /p id=Instance Id:
    set /p name=AMI name:
    "C:\Program Files\Amazon\AWSCLI\aws.exe" ec2 create-image --instance-id %id% --name %name%
    

    Now you have created an Amazon Machine Image — an image of the whole instance with all operating system and software configurations. Now it’s time to launch.

    FREE WHITEPAPER
    Backup and Disaster Recovery on AWS
    Every minute of downtime means money lost.
    Plan your perfect disaster recovery strategy on AWS:
    New call-to-action
    WP icon

    Step 2: Launch created AMI in the desired Availability Zone / VPC / AWS Region

    • If you want to migrate EC2 instance to another region, then under the EC2 section choose AMIs, right-click your AMI and choose Copy AMI

    AWS: change Region, Availability Zone or VPC - Copying AMI

    • Select a destination region and a new name for your AMI. Switch to your destination region and go to the next section.

    AWS: change Region, Availability Zone or VPC - New AMI settings

    Here is an AWS CLI script:

      New call-to-action
    @echo off
    set /p id=AMI id:
    set /p region=Source region:
    "C:\Program Files\Amazon\AWSCLI\aws.exe" ec2 copy-image --source-region us-east-1 --source-image-id %id% --name "Migrated"
    

    Note: Before you run the script, run "C:\Program Files\Amazon\AWSCLI\aws.exe" and specify your destination region as a default.

    • If you need to move an instance to a different Availability Zone or VPC, choose AMIs under the EC2 section, right-click your AMI and choose Launch. (Learn how to create S3 VPC endpoint if needed.)

    AWS: change Region, Availability Zone or VPC - Launching new EC2 instance from AMI

    • Choose an Instance type at the first step. Then choose desired VPC and desired subnet under the Configure Instance Details section. Also, you will be asked to specify other settings such as Storage, Tags and Security groups.

    AWS: change Region, Availability Zone or VPC - Creating new VPC and subnet

    Now you know how to successfully migrate EC2 instance to another region, Availability Zone, VPC by using native AWS tools. Notice that you don't have to stop it to perform a migration, therefore you don't have to spend more time and money than needed.

    WP icon
    FREE WHITEPAPER
    Mastering AWS IAM for Amazon S3
    • Introduction to Amazon S3 access tools
    • Writing IAM policies
    • Mastering Amazon S3 identities
    New call-to-action