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

5 minute read
3

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

You can't move an existing instance to another subnet, Availability Zone, or VPC. Instead, you must create a new Amazon Machine Image (AMI) from the source instance. Then, use the new AMI to launch a new instance in the new subnet, Availability Zone, or VPC. Finally, reassign all Elastic IP addresses from the source instance to the new instance.

To migrate your instance, use one of the following methods:

  • Use the AWSSupport-CopyEC2Instance runbook to automatically create a new AMI and new instance.
  • Manually launch the instance from an AMI.

Resolution

Prerequisites:

When you create an AMI, you don't automatically create a snapshot for instance store volumes on the instance. For more information, see How do I back up an instance store volume on my Amazon EC2 instance to Amazon EBS?

Use the AWSSupport-CopyEC2Instance runbook to create a new AMI and new instance

You must run the AWSSupport-CopyEC2Instance runbook in the same AWS Region as the instance.

To run the runbook, complete the following steps:

  1. Open the AWSSupport-CopyEC2Instance runbook.
  2. For Execute automation document, choose Simple execution.
  3. For Input parameters, enter the instance ID of the instance that you want to copy for InstanceID. If you use the interactive instance picker, then select Show all instances.
  4. For Region and SubnetID, enter the destination Region or subnet ID where you want to copy the instance.
  5. Complete the relevant optional fields, and then choose Execute.
  6. To monitor progress, open the AWS Systems Manager console, and then choose Automation in the navigation pane.
  7. Choose the running automation, and then review the Executed steps. To view the automation output, expand Outputs.

After the runbook completes, proceed to the Reassign the Elastic IP addresses section.

Manually launch the instance from an AMI

Create a new AMI from the instance.

Then, complete the following steps to launch a new instance from the AMI:

  1. Open the Amazon EC2 console.
  2. In the navigation pane, choose AMIs.
  3. Set the filter to Owned by me, and then select the new AMI.
  4. Choose Launch instance from AMI.
  5. Under Name and tags, enter a name for your new instance for Name. You can use the existing name and tags.
  6. Under Instance type, select the same instance type as the instance that you're moving.
  7. Under Key pair (login), for Key pair name, select the key pair that the instance that you're moving uses.
  8. Under Network settings, configure the following settings:
    For Network, choose the that VPC you want to move to.
    For Subnet, choose the subnet where you want to launch the new instance.
    For Firewall (security groups), choose the same security group that you use on the instance that you're moving.
    Note: If you're moving your instance between VPCs, then you must create a new security group in the destination VPC.
    (Optional) Configure the remaining fields based on your new instance's requirements.
  9. Under Configure storage, keep the default settings, or modify the storage settings.
  10. Expand the Advanced details section, and then add parameters based on your instance configuration requirements.
  11. Under Summary, review a summary of your instance configuration, and then choose Launch instance.
  12. When the instance launches, you receive a Success message. To check the instance status, choose the instance ID in the Success message.

Reassign the Elastic IP addresses

Note: The new instance has a different private IPv4 or public IPv6 IP address. Update all references to the previous IP addresses, such as DNS entries, with the new IP addresses. If you use an Elastic IP address on your source instance, then you must attach it to the new instance.

To reassign an Elastic IP address, disassociate the Elastic IP address from the source instance. Then, associate the Elastic IP address with the new instance. You can use the Elastic IP address in only one Region. If you move an instance to a different Region, then you can't use the same Elastic IP address.

Important: After you verify that your new instance is working as expected, deregister the AMI and delete associated snapshots that you no longer need.

Related information

Create an Amazon EBS-backed AMI

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

3 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 a year ago

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

profile pictureAWS
MODERATOR
replied a year ago

You can delete the AMI and Snapshot after the new instance is running. Don't forget to clean up after you do something like this, or you'll end up paying for that snapshot for years in the future!

profile picture
replied 3 months ago