0

I have a php/mysql website that I want to deploy on AWS. Ultimately, I'm going to want auto-scaling (but don't need it right away).

I'm looking at an EBS based AMI. I see that by default the "Root Device Volume" is deleted when an instance "terminates". I realize I can also attach other EBS devices/drives to an instance (that will persist after termination) but I'm going to save most user content in S3 so I dont think that's necessary. I'm not sure how often I'll start/stop vs when i would ever want to terminate. So that's a bit confusing.

I'm mostly confused with where changes to the system get saved. Say I run a YUM install or update. Does that get saved in the "root device volume"? If i stop/start the instance, the changes should be there? What about if I setup cron jobs?

How about if I upload files? I understand to an extent that it depends where I put the files and if I attached a second EBS. Say I just put them in the root folder "/" (unadvised, but for simplicity sake). I guess that they are technically saved in the "root device volume"? If I start/stop the instance, they should still be there?

However, if I terminate an instance, then those changes/uploads are lost. But if I set the "root device volume" to not delete on termination, then I can launch a new instance with the changes there?

In terms of auto-scaling. Someone said to leave the "root device volume" to default delete so that when new instances are spun up/shut down, they don't leave behind zombie EBS volumes that are no longer needed (and would require manual clean-up)?

Would something like this work: ?

  1. Setup S3 bucket (for shared image uploads)
  2. Setup Amazon RDS / mysql
  3. Setup DynamoDB (for sharing php sessions)
  4. Launch EBS-backed AMI (leave as default to delete "root device volume" on termination). Make system updates using yum/etc. Upload via sftp PHP/HTML/JS/CSS files (ex: /var/www/html). Validate site can save images to S3, share sessions via DynamoDB, access mysql via RDS.
  5. Make/clone your own AMI image from your currently running/configured one. Save it with a name that indicates site version/date/etc.
  6. Setup auto-scaling to launch the image created in #5

I'm mostly concerned with how to save my configuration so that 1) changes are saved in-case i ever need to terminate an instance (before using autoscale) and 2) that auto-scaling will have access to the changes when I'm ready for it. I also don't want something like the same cron-job running on all auto-scaling instances.

I guess I'm confused with "does creating my own AMI image in #4" basically replace the "saving EBS root device volume" on termination? I can't wrap my head around the image part of things vs the storage part of things.

I get even more confused when I read about people talking about if you use "Amazon Linux" then the way they deploy updates every 6 months makes it difficult to use because you are forced to use new versions of software. How does that affect my custom AMI (with my uploaded code)? Can I just keep running yum updates on my custom AMI (for security patches) and ignore any changes to amazon's standard AMIs? When does the yum approach put me at risk for being out-of-date?

I know there are a host of things I'm not covering (dns/static IPs/scaling metrics/etc). That instead of uploading files then creating an AMI image, some people have their machine set to pull files from git on startup (i dont mind my more manual approach for now). Or that i could technically put the php/html/css/js on S3 too.

Sorry for all of the random questions. I know my question might not even be totally clear, but I'm just looking for confirmation/advice in-general. There are so many concepts to tie-together.

Thanks and sorry for the long post!

user3249281
  • 505
  • 2
  • 6
  • 20

1 Answers1

1

Yes, if you install packages, upload files, set up cron jobs, etc. and then stop the EBS-based instance, everything will still be there when you restart it. Consequently, if you create an AMI from that instance and then use it for your autoscaling group, all the instances of the autoscaling group will run the cron jobs.

Your steps look good. As you are creating an AMI, your changes will be saved in that AMI. If the instance is terminated, it can be recreated via the AMI. The modifications made on that instance since the AMI creation will not be saved though. You need to create an AMI or take a snapshot of the EBS volume if you want a backup.

If you make a change and want to apply it to all the instances in the autoscaling group, you need to create a new AMI and apply it to your autoscaling group.

Concerning the cron jobs, I guess you have 2 options:

  • Have 1 instance that is not part of the autoscaling group running them (and disable the cron jobs before creating the AMI for the autoscaling group)
  • Do something smart so only one instance of the autoscaling group runs them. Here is the first page I hit on Google: https://gist.github.com/kixorz/5209217 (not tested)

Yes, creating your own AMI image basically replaces the "saving EBS root device volume" on termination.

An EBS boot AMI is an EBS snapshot of the EBS root volume plus some metadata like the architecture, kernel, AMI name, description, block device mappings, and more.

(From: AWS Difference between a snapshot and AMI)

Yes, you can automatically run yum security updates. To be completely identical to the latest Amazon Linux AMI, you should run all yum updates (not only security). But I wouldn't run those automatically.

Let me know if I forgot to answer some of your questions or if some points are still unclear.

Community
  • 1
  • 1
Céline Aussourd
  • 10,214
  • 4
  • 32
  • 36
  • Great feedback! Re: "As you are creating an AMI, your changes will be saved in that AMI". Basically, the EBS can be thought of as hardware-only (like a VM) and the image itself is actually what contains the changes. If I create a new AMI from the current one, I'm "saving" my changes in-case of instance termination or wanting to auto-scale. Terminate the instance without creating a new AMI clone (or snapshot) and all the changes are gone (not because the EBS gets wiped but because the image is essentially dropped). So the EC2 "machine" and EBS are strictly hardware and all code is in the image? – user3249281 Jan 20 '17 at 19:01
  • Also, everything you said about cron makes total sense. I imagine at some point i'll have a more "micro-services" strategy but for now I'll have an isolated cron machine outside of auto-scale to take of those scheduled worker jobs. Lastly, when you say you wouldn't run yum updates automatically, you mean you would test all updates in some UAT environment before doing it in PROD? Like basic change management. Just want to make sure there is no downside to manual updates vs trying to use the latest amazon linux bi-annuals. – user3249281 Jan 20 '17 at 19:06
  • @user3249281 Yes, that's what I mean concerning the updates. I would recommend to run the security updates though. – Céline Aussourd Jan 20 '17 at 22:47
  • No, the AMI is a snapshot of the EBS volume + metadata. If you terminate an instance. The AMIs and snapshots ate not deleted. They are independent entities. I would think of the EBS as an hard drive only. An EBS snapshot is an image of that hard drive as a certain point. – Céline Aussourd Jan 20 '17 at 22:53