92

Sometimes when trying to launch my t1.micro EC2 instance, it cannot be provisioned and Amazon recommends trying a different availability zone. Is it possible to change this for an existing instance?

anon
  • 4,163
  • 3
  • 29
  • 26

1 Answers1

106

You cannot move an existing EC2 instance to a different availability zone directly.

However, the following approach can be used to move an instance to a different availability zone indirectly through a new AMI:

  1. Stop (do not terminate!) the old instance in the old availability zone.

  2. Create an AMI based on the old instance.

  3. Run a new instance of the new AMI in the new availability zone. It will be a fairly exact copy of your old instance.

If you were using an Elastic IP address, re-associate it with the new instance.

Once you have tested the new instance and know that it's working well, terminate the old instance in the old availability zone.

Eric Hammond
  • 22,089
  • 5
  • 66
  • 75
  • 51
    wtf does "fairly exact copy" that worries me bro – benathon Jun 30 '12 at 23:19
  • 19
    portforwardpodcast: The new instance will be started with a different AMI id, different instance id, different EBS volume id and possibly different user-data (you decide what to pass in). Depending on the software and configuration of the instance, this could affect how it starts up and behaves. Otherwise, the file system on the instance will be as if you shut it down and restarted it. – Eric Hammond Jul 03 '12 at 16:19
  • 1
    maybe an update for users stumbeling on the same question: between steps 2 and 3 you now need to copy your instance into another availability zone via right click on the AMI. And you don't need necessarily to stop the instance, so you can skip step 1. – lordvlad Sep 12 '13 at 14:49
  • @lordvlad There is no such thing as "copy your instance into another availability zone via right click on the AMI". You simply need to run a new instance of the AMI in the availability zone, which is step 3. If you don't stop the instance when creating the AMI, you risk having an inconsistent file system or database in the snapshot. In fact, EC2 stops the instance for you when you use the "create-image" API or Console function. – Eric Hammond Sep 12 '13 at 20:41
  • I'm sorry, I meant copy AMI via right click. When I tried to launch the AMI after creation, I could only choose the subnet (Us-west1a/us-west1b/us-west1c) but wasn't able to launch the instance in, say, Europe. But when I right-clicked the AMI I cold choose it to copy into another zone. As for not stopping the instance: it MAY cause data loss, you are right, but AFAIK only when there are I/O operations at the time. I never had trouble, but I guess the better practice is to stop the instance. – lordvlad Sep 12 '13 at 23:59
  • 2
    @lordvlad You are confusing "availability zone" and "region". Each region has multiple availability zones. An AMI exists in a region and can be run as an instance in any availability zone in the region. The original question here is about availability zones. – Eric Hammond Sep 13 '13 at 01:29
  • 3
    As of December, 2012, Amazon now supports migrating an AMI to another region through the UI tool (Amazon Management Console). See http://stackoverflow.com/a/14205963/423171 – cprcrack Jun 07 '15 at 13:56
  • Note: If you choose to copy between regions rather than just AZs keep in mind that communications between regions happens across the public internet. This means that a) you'll be charged the relevant Internet data transfer rates on both sides, and b) security considerations may apply. – StvnW Jan 29 '16 at 19:14