0

I have an EC2 instance on AWS that is currently hosting a simple Webserver using nginx and python-flask. The OS on the instance is Ubuntu 16.04.

I am concerned about a potential server failure, so I want to set up AWS CloudWatch to automatically spin the server back up, should it fail.

What I'm trying to now understand is whether CloudWatch will restore the files on my server, so that the web-server will keep running smoothly (providing I specify a script to restart nginx and my flask app), or whether the new server will be a fresh Ubuntu instance, such that I need to supply a configuration file to pull all the files, install dependencies, launch nginx, etc.

Newb
  • 103
  • 3

1 Answers1

2

EC2 instance recovery does this. It will try to recover your server with all files, but that might not always be possible.

You can't rely on instance recovery. You'd be better off making regular snapshots of your EBS disk for backup, and creating an AMI that you can easily start. You can autoscale one instance, so if your instance fails it will start another for you.

Alternate, you can build your whole environment including VPC and servers using CloudFormation. You may have to use OpsWorks (Chef) for some of the detailed setup. This gives you "infrastructure as code", so you can easily spin up more servers. These take longer to launch than an AMI.

If you move your logs and data off the EBS / instance store to S3, CloudWatch Logs (logs only), or somewhere else, then you probably don't need to have a really fresh AMI. Just run your apt-get update / upgrade when the instance come up, using a script.

Tim
  • 30,383
  • 6
  • 47
  • 77
  • To follow up: how should I think about the disk of my server? It's neither EBS nor Instance Store, right? – Newb Mar 25 '17 at 00:45
  • Suggest you need to do some reason on the basics of AWS. The vast majority of EC2 instances use Elastic Block Store (EBS) as their disk. This is a network disk. A small number of instance have locally attached storage, called the instance store. You want to be using EBS, and you want to be taking snapshots for backup regularly. You can automate snapshot creation, just Google it. I have mine weekly because they don't change very often, and I run nightly backups inside the OS. – Tim Mar 25 '17 at 00:55
  • thanks for the help. One more question: I just rebooted my EC2 instance, and I noticed that nginx was automatically running again, after the reboot. Do you know why that might be? Could it be because I'm using `AWS CodeDeploy`, so there's an `appspec.yml` that says to restart nginx? – Newb Mar 25 '17 at 01:14
  • 1
    Nginx will have been set to run on startup. I don't know anything about CodeDeploy sorry, but not sure that's it. Service startup is a little complex, there are a few different technologies that can be in place - Upstart, System D, etc. I spent a few hours reading up on it recently so I have a little of an idea. Short version: look in the /etc/init.d directory for an nginx script, that will run on startup, as will everything in that directory. ie /etc/init.d/startup . If you have a full question on startup ask it separately, easier that way. – Tim Mar 25 '17 at 01:19