How do I move my EC2 instance to another subnet, Availability Zone, or VPC?
Last updated: 2021-08-16
I want to move or copy my Amazon Elastic Compute Cloud (Amazon EC2) instance to another subnet, Availability Zone, or virtual private cloud (VPC). How do I do that?
It's not possible to move an existing instance to another subnet, Availability Zone, or VPC. Instead, you can manually migrate the instance by creating a new Amazon Machine Image (AMI) from the source instance. Then, launch a new instance using the new AMI in the desired subnet, Availability Zone, or VPC. Finally, you can reassign any Elastic IP addresses from the source instance to the new instance.
There are two methods for migrating the instance:
- Use the AWS Systems Manager automation document AWSSupport-CopyEC2Instance.
- Manually copy an instance and a launch a new instance from the copy.
Before you begin, note the following:
- 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 on backing up instance store volumes to Amazon EBS, 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. You must 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're using an Elastic IP address on your source instance, 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
You can 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 needed.
To run the automation, do the following:
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 make sure that you select Show all instances from the dropdown list.
4. Provide the destination Region and/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 execution 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
- Open the Amazon EC2 console, and then choose Instances from the left navigation pane.
- Select the instance that you want to move, and then choose Actions, Instance State, 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.
- Choose Actions, Image, 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 can't be guaranteed.
- Choose Create Image.
- Under Create Image request received, choose View pending image [ID]. Wait for the Status to change from pending to available.
Note: You can also view pending images by choosing AMIs from the Images section of the navigation pane.
Launch a new instance
- Select the new AMI, and then choose Launch.
- 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.
- Choose Next: Add Storage.
- Accept the defaults, and then choose Next: Add Tags.
For Key, enter Name.
For Value, enter your instance name.
- Choose Next: Configure Security Group.
- Choose the same security group that's applied to the instance that you're moving.
Note: If you're moving your instance between VPCs, you must create a new security group on the destination VPC.
- Choose Review and Launch.
- Choose Launch.
- For Select a key pair, choose your key pair from the drop-down menu.
- Select the agreement check box, and then choose Launch Instances.
- 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, you can reassociate the Elastic IP address with the new instance. For instructions, see Disassociate an Elastic IP address.
Note: Elastic IP addresses can be used in only one Region. If you move an instance to a different Region, you can't use the same Elastic IP address.