Amazon EC2 – What Happens If an Instance is Shut Down and Restarted?

amazon ec2amazon-web-servicesdomain-name-systemlinux

I have a web site that runs on an Amazon EC2 Linux-based instance, and is mapped to a regular domain name (x.com). This site talks to a database on a second EC2 instance.

I need to shut down this instance and increase the computing power behind it… if I do that, how long will it take, and then when I spin the machine up again, will my site just come back online? Will the IP address, DNS info etc. all be preserved so the domain name will keep working, and it will still be able to talk to the DB?

FYI this is what I currently see for the web server in the AWS EC2 info panel (exact IP addresses changed slightly but you get the idea):

Public DNS: ec2-54-1-1-1.us-west-1.compute.amazonaws.com
Private DNS: ip-10-1-1-1.us-west-1.compute.internal
Private IPs: 10.1.1.1

Best Answer

Stopping and starting an EBS boot instance is very similar to simply rebooting the instance with a few exceptions, the most notable being:

  1. The instance is assigned a new internal IP address.

  2. The instance is assigned a new public IP address.

  3. If the instance is not in a VPC, then any Elastic IP address is disassociated with the instance.

  4. All data on ephemeral storage (often under /mnt) is lost

There are also some billing and availability implications which I described in this article:

Rebooting vs. Stop/Start of Amazon EC2 Instance
http://alestic.com/2011/09/ec2-reboot-stop-start

VPC instances have slightly different behavior including keeping Elastic IP addresses through stop/start.

If you are using an instance as a database server and you want to connect to it using the internal IP address (cheaper, faster) and you don't want to have to reconfigure the database clients after a stop/start, then you can assign an Elastic IP address to the instance and use the external Elastic IP DNS name. This will resolve to the current internal IP address after you re-associate the Elastic IP address to the restarted instance and your clients will pick up where they left off.

I go into more detail about this approach in this article:

Using Elastic IP to Identify Internal Instances on Amazon EC2
http://alestic.com/2009/06/ec2-elastic-ip-internal

As it sounds like you've anticipated, stop/start is an easy way to change the hardware powering your instance. I wrote about this along with some instructions and warnings in this article:

Moving an EC2 Instance to a Larger (or Smaller) Instance Type
http://alestic.com/2011/02/ec2-change-type

For your particular situation I would recommend assigning an Elastic IP address to the instance and changing your DNS to point to the Elastic IP address using a CNAME to the external DNS name. You could do this right after the stop/start, or you could do it ahead of time making sure everything works before the stop/start.