10

I am using a Web & DB Instances in AWS EC2 and I want to make them high available, so that if one server fails (primary server), then another one is turned on (secondary server).

I have found lots of information for RDS high availability but not for EC2 instances that are not RDS.

  1. Could you please provide me some links for a good guide of how doing it?
  2. Could you please tell me in some words what is the process I should do in order to achive the high availability?

Thanks.

Misha Zaslavsky
  • 4,808
  • 10
  • 44
  • 95

3 Answers3

16

there are several possibilities to achieve HA with EC2:

  • create an autoscaling group with min capacity=1 and max capacity=1. So whenever your instance fails, the autoscaling group will create a new one. The autoscaling group comes for free, so this is not a bad solution depending on your SLA.
  • use ec2 auto-recovery feature by creating a cloudwatch alarm that would replace your instance if failed.
  • create two EC2 instances and use Route 53 DNS failover to resolve to an healthy instance
  • Last but not least: the best solution is definitely to create several instances across several availability zones and to use an elastic load balancer to distribute the traffic. This way, even if an instance fails, you already have other ones available. AWS recommends this solution as they have an SLA of 99.95% for their instance in an AZ. By putting in several AZs you can have 100% availability

EDIT: adding information why there is no such native feature for EC2.

there is no native HA feature in EC2 compared to RDS, because EC2 is pure IaaS when RDS is more PaaS. So for RDS when you select HA, behind the scene it actually spawns a slave database in another availabilty zone and replicates your master. Whenever the master fails, you have an automatic DNS failover to the slave database, which is elected master, and a new slave database is getting created.

Tom
  • 2,260
  • 12
  • 20
  • "have an SLA of 99.95% for their instance in an AZ" - the quoted number (now updated to 99.99%) is for a _region_, not an AZ. Therefore, one must use a multi-AZ deployment to get that level of availability. https://aws.amazon.com/ec2/sla/ – Ned Lowe Mar 13 '18 at 02:22
7

The question you should ask is - how do I make my application HA on AWS, not how do I make EC2 HA. And the short answer is that you must tell AWS how you define and deploy your application first.

In the case of RDS, it is abundantly clear what the application is - it is the database server of your choice. At the most basic, AWS can setup an HA instance of RDS with default settings without much input from you.

However, in the case of your application, you need to give AWS more details. There are several ways to do this:

  • create an ELB with a bunch of EC2 instances in different availability zones
  • create an ELB with an auto-scaling group which will lead you down the path of creating an AMI and a launch configuration; in this mode, you can even tell ASG to use the ELB health check to determine when an EC2 instance is no longer healthy
  • you didn't mention what your application is, but you might want to get CodeDeploy involved to tell AWS how to deploy latest code to a newly spun up EC2 instance; CodeDeploy works well in tandem with ELB and ASG
  • instead of defining the above components individually, you could define them together in an Elastic Beanstalk; this is the determination you'll have to make on your own - do you want more flexibility by defining individual components on your own, should you simplify things and use EB?
  • lastly, if you use Docker and you can dockerize your applications or different components of the same application, AWS supports EB with multi-container docker

Whichever route you decide, AWS CloudFormation templates are a good way to tie everything together and define your stack. One advantage of this is whenever you need to make a change in your stack, you'll change your CloudFormation template, apply the change and let AWS figure out what the dependencies are, what order to update them and how.

Unix One
  • 1,111
  • 7
  • 14
3

How about using Elastic Beanstalk (for official documentation see here)?

Essentially it making use of many AWS services in the using the configuration detailed here.

Its main purpose is to make it easier to create several sets of environments for running your apps, while monitoring the health and load of your application and bringing up instances to distribute the load.

It is however possible to use configure your environment as a single instance (see the main documentation under the section Environment Types). That means that you can take advantage of the health monitoring and AWS will take care of the availability.

More specifically to answer your questions: 1) Official AWS Documentation is quite detailed and should get you started. There are several video resources explaining the basic setup

2) You could combine several EBS instances in different regions to keep your servers close to your traffic.

Convolu
  • 31
  • 3