How do I move my EC2 instance to another subnet, Availability Zone, or VPC?

5 minute read
2

I want to move or copy my Amazon Elastic Compute Cloud (Amazon EC2) instance to another subnet, Availability Zone, or virtual private cloud (VPC).

Short description

It's not possible to move an existing instance to another subnet, Availability Zone, or VPC. Instead, you can create a new Amazon Machine Image (AMI) from the source instance to manually migrate the instance. Next, use the new AMI to launch a new instance in the desired subnet, Availability Zone, or VPC. And finally, reassign any Elastic IP addresses from the source instance to the new instance.

There are two methods to migrate the instance:

  • Use the AWS Systems Manager automation document AWSSupport-CopyEC2Instance.
  • Manually copy an instance and a launch a new instance from the copy.

Resolution

Before you begin, review the following information:

  • AMIs are based on Amazon Elastic Block Store (Amazon EBS) snapshots. For large file systems without a previous snapshot, AMI creation can take several hours. To decrease the AMI creation time, create an Amazon EBS snapshot before you create the AMI.
  • Creating an AMI doesn't create a snapshot for instance store volumes on the instance. For information, see How do I back up an instance store volume on my Amazon EC2 instance to Amazon EBS?
  • The new EC2 instance has a different private IPv4 or public IPv6 IP address. Update all references to the old IP addresses (for example, in DNS entries) with the new IP addresses that are assigned to the new instance. If you use an Elastic IP address on your source instance, then be sure to attach it to the new instance.
  • Domain security identifier (SID) conflict issues can occur when the copy launches and tries to contact the domain. Before you capture the AMI, use Sysprep or remove the domain-joined instance from the domain to prevent conflict issues. For more information, see How can I use Sysprep to create and install custom reusable Windows AMIs?

Use the AWS System Manager automation runbook AWSSupport-CopyEC2Instance

Use the AWS Systems Manager Automation runbook AWSSupport-CopyEC2Instance to complete the following tasks automatically:

  • Create a new image
  • Launch a new instance

After these procedures complete, follow the instructions in Reassign the Elastic IP address section, if it's required.

To run the automation, complete the following steps:

  1. Open the AWSSupport-CopyEC2Instance runbook.
    Note: Make sure that you're in the same Region as the instance that you want to copy.
  2. For Execute automation document, choose Simple execution.
  3. For Input parameters, enter the InstanceID of the EC2 instance you want to copy. If you use the interactive instance picker, then select Show all instances from the dropdown list.
  4. Provide the destination Region or the SubnetID where you want to copy the instance to.
  5. Complete any of the additional optional fields that are required for your use case, and then select Execute.
  6. To monitor the progress, open the Systems Manger console, and then choose Automation from the navigation pane. Choose the running automation, and then review the Executed steps. To view the automation output, expand Outputs.

For more information about this runbook, see AWSSupport-CopyEC2Instance.

Manually copy the instance and launch a new instance from the copy

Create a new image

  1. Open the Amazon EC2 console, and then choose Instances from the left navigation pane.
  2. Select the instance that you want to move. Choose Actions, then choose Instance State, and then choose Stop. This makes sure that the data is consistent between the old and new EBS volumes.
    Note: You can skip this step if you're testing this procedure or if you don't want to stop or reboot your instance.
  3. Choose Actions, then Image, and then choose Create Image.
    For Image name, enter a name for the image.
    For Image description, enter a description of the image.
    Note: If you select No reboot on the Create Image page, then the file system integrity of the image might be compromised.
  4. Choose Create Image.
  5. Under Create Image request received, choose View pending image [ID]. Wait for the Status to change from pending to available.
    Note: You can also choose AMIs from the Images section of the navigation pane to view pending images.

Launch a new instance

  1. Select the new AMI, and then choose Launch.
  2. Choose the same instance type as the instance that you want to move, and then choose Next: Configure Instance Details.
    For Network, choose your VPC.
    For Subnet, choose the subnet where you want to launch the new instance.
    If the instance is a production instance, then for Enable termination protection, choose Protect against accidental termination.
  3. Choose Next: Add Storage.
  4. Accept the defaults, and then choose Next: Add Tags.
    For Key, enter Name.
    For Value, enter your instance name.
  5. Choose Next: Configure Security Group.
  6. Choose the same security group that's applied to the instance that you're moving.
    Note: If you're moving your instance between VPCs, then you must create a new security group on the destination VPC.
  7. Choose Review and Launch.
  8. Choose Launch.
  9. For Select a key pair, choose your key pair from the dropdown list.
  10. Select the agreement check box, and then choose Launch Instances.
  11. Choose the instance ID to return to the EC2 console.

Reassign the Elastic IP address

To reassign the Elastic IP address, you must first disassociate the Elastic IP address from the source instance. Then, reassociate the Elastic IP address with the new instance. For instructions, see Describe your Elastic IP addresses.

Note: Elastic IP addresses can be used in only one Region. If you move an instance to a different Region, then you can't use the same Elastic IP address.

Related information

Create an Amazon EBS-backed Linux AMI

Create a custom Windows AMI

How do I create an AMI in one AWS Region and then copy it to another?

2 Comments

With the new multi-homed instances the secondary ENI can be in a different subnet or even VPC as long as it is in the same account and zone. Wouldn't that be a way to more simply move an EC2? See

profile picture
replied 18 days ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
MODERATOR
replied 18 days ago