0

I'm about to start using AWS for the first time. From what I understood, when you terminate an instance or start a new one, all the data is lost. For user data I understand you are supposed to use cloud storage such as S3. That's ok.

Now what about all the configurations? Say I spend 2 hours setting up all the apache and PHP configuration or whatnot. How do I make sure it's still there when I terminate an instance, or start a new one?

Secondly, what about my actual app, the PHP code in my case, as well as the file permissions needed to run it? What happens when I terminate the instance? What if I have 3 instances and make changes to my code?

Sorry very new to this whole concept.

Thanks

nute
  • 791
  • 2
  • 11
  • 22

2 Answers2

1

There are 2 types of EC2 instances: (a) Instance Store - This type of instance has it's root volume on a hardware hard drive. You cannot stop this type of instance, it can only be terminated. When terminated, all data on that hard drive is lost. (b) EBS-backed - This type of instance has it's root volume on an EBS volume. EBS volumes are persisted and stored away from the EC2 instance. These types of instances can be stopped and restarted without loss of data from the EBS volumes.

EBS-backed instances are the preferred instance types because of the ability to backup and restore the volumes and the ability to stop and start your instances.

In either case, data is lost of you terminate your instance. You can create AMI images of your EC2 instances, which can then be used to create new copies of your instance.

Matt Houser
  • 10,053
  • 1
  • 28
  • 28
  • What is the difference between terminating and stopping? Do I continue to pay in one of the cases? Do I ever need to terminate? – nute Oct 24 '12 at 07:40
  • Stopping is like turning off your server. You can turn it back on later. Terminating is like erasing the hard drive: it's gone forever. – Matt Houser Oct 24 '12 at 23:58
1

Create an EBS volume and attach it to your instance. After you install your services (e.g. Apache, MySQL, PHP, etc) move the respective files to your EBS storage.

For example, I run Ubuntu on my instances and therefore all of the necessary configuration information for each service is contained in a respective directory under /etc (e.g. /etc/apache2, /etc/php, and so on). After mounting an EBS volume to /vol I then moved the /etc/{service} directory to /vol. So PHP went from /etc/php5 to /vol/etc/php5. I then symlinked /etc/php5 to /vol/etc/php5. The only "gotcha" is with MySQL you should also do the actual data directory of /var/lib/mysql as well.

Now if my instance dies or I terminate it all of the configurations are saved on the EBS, which I can then clone or attach to any other instance. Since I also placed /var/www/ on the EBS volume my websites and all their data are there as well.

daemonofchaos
  • 1,211
  • 1
  • 8
  • 10
  • Matt Houser above wrote that in both cases terminating the instance will erase data. It seems to contradict your answer, or are you saying something different? – nute Oct 24 '12 at 07:39
  • Matt Houser is incorrect that EBS data is lost upon termination of the instance. The only way that EBS data is lost is when you destroy the EBS volume itself. Please see http://aws.amazon.com/ec2/faqs/ and specifically the http://aws.amazon.com/ec2/faqs/#What_is_the_difference_between_using_the_local_instance_store_and_Amazon_Elastic_Block_storage_for_the_root_device section. – daemonofchaos Oct 24 '12 at 14:24
  • I was unclear. By default, the root ebs volume will be deleted when you terminate the instance. Unless you modify the volume attachment to not delete the volume upon termination, you will lose data. – Matt Houser Oct 24 '12 at 23:47
  • The best way to do it is as I suggested and create a separate EBS volume that your data and configuration information is stored on. This type of volume is not affected by the status of the instance. – daemonofchaos Oct 25 '12 at 03:08