How do I move my EC2 instance to another subnet, Availability Zone, or VPC?
Last updated: 2019-06-12
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?
To move an EC2 instance:
- Create a new Amazon Machine Image (AMI) from the source instance.
- Use the AMI to launch a new instance.
- Reassign the Elastic IP address from the instance you are moving to the new image.
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, creating an AMI can take several hours. To decrease the AMI creation time, first create an Amazon EBS snapshot before creating 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 will have 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 old instance, be sure to attach it to the new instance.
Create a new image
- From the EC2 console, choose Instances from the left navigation pane.
- Choose the instance that you want to move, choose Actions, choose Instance State, and then choose Stop. This assures 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, and then Create Image.
Note: If you select No reboot, the file system integrity of the image can't be guaranteed.
- Choose View pending image ID. Wait for the Status to change from pending to available.
Launch a new instance
- Choose the new AMI, and then choose Launch Instance.
- Choose the same instance type as the instance you want to move, and choose Next: Configure Instance Details.
- For Network, choose your VPC, and for Subnet, choose the subnet where you want to launch the new instance.
- If the instance is a production instance, choose Protect against accidental termination, and then choose Next: Add Storage.
- Accept the defaults, and then choose Next: Add Tags.
- For Key, enter Name, and 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. Choose Review and Launch.
Note: If you're moving your instance between VPCs, you must create a new security group on the destination VPC.
- Choose Launch.
- In 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
Follow the steps at Disassociating an Elastic IP Address and Reassociating with a Different Instance.
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.