How can I move EC2 instances to a different subnet?
Solution 1:
Creating smaller subnets is pretty straight forward. Delete the subnet and create new subnets. However, you'll want to transition off the boxes in B/24 before you delete it.
Now, moving a running machine between subnets is not possible*. Depending on your application and your requirements, I imagine that shutting it down, taking an image of the machine, then launching a new instance of that machine in the other subnet will work.
*As an aside, I wondered if you could attach a new network interface from a new subnet and then remove your old network interface, effectively moving subnets without having the take the box down. As it turns out, you cannot remove the network interface at index 0, which means this does not work.
Solution 2:
Maybe you only need to "access" a different subnet...
It's true that you will never get the AWS web console to display any other value for "Subnet ID" in the instance details. Others have explained how to create new instances that will "be on" the desired subnet. I needed to take an existing server running software that was licensed to "one non-transferable Host ID" and "put it on" a different subnet. (Of course when I say licensed software, I'm talking about Windows software from a vendor who "doesn't support AWS"!) I solved this by:
- Create a new network interface (AWS > EC2 > Network Interfaces) on the desired subnet and the same availability zone as the machine.
- Attach the new nic to the machine. (AWS > EC2 > Actions > Networking > Attach Network Interface)
- In Windows the interface just appeared!
- Set the "Metric" ("priority" integer, lowest wins) of each Network Connection (Control Panel > Network and Internet > Network Connections > [double-click connection name] > Properties [button] > TCP\IPv4 > Properties [button] > Advanced [button] > Automatic Metric [uncheck] > Interface metric)
- To confirm the routing table call
route print
from the command line.
Now everything the machine does is on the desired subnet. It is still reachable on the old IP (and previous subnet) as well as on the new IP (and desired subnet).
This is a pretty narrow case, but I hope it helps someone.
Solution 3:
Only way is to stop then create AMI, then launch from the image in AZ of your choice (as of Apr 2015)
Solution 4:
You can create new instance in the target subnet, but same AZ, and then detach/reattach the EBS volumes from the original (including the root volume) to the new instance. This may result in a shorter downtime because you can create the new instance will the original is running but is a bit more complex to carry out.