6

I'm using the AWS Free Tier, which gives me one free EC2 microinstance and one free Elastic Load Balancer, if I understand things correctly.

I understand that usually ELBs are used when you are using multiple EC2 instances. I don't really want to run multiple instances if I can help it, and 90% of the time my single EC2 instance seems to handle the traffic that is thrown at it, but occasionally it gets unresponsive and needs to be rebooted. It doesn't seem to do this automatically.

I read the ELBs will restart microinstances that it dubs "unhealthy" (unresponsive to multiple ping attempts). So one idea I had was to create a single ELB, assign my single EC2 to it, and therein create an easy "auto-reboot if it gets stuck" situation.

I've set it up, and it didn't balk or bark at me, but I was wondering if I'm understanding this right. I'm fairly new to server administration and only just getting into concepts like micro-instances and ELBs and whatever, though (like all fools) I think I understand the basics of it.

Is this a good idea? Is there an easier way to accomplish this? I've tried to Google and search for other people doing this same thing and not found anyone, but I can't tell if that's because it won't work or because nobody else is foolish enough to try and use a single EC2 micro instance for all of their traffic. I am deeply suspicious that it is a bad idea since I don't see anyone else talking about it, and while I am fairly clever about some things, I'm not too confident about being clever in these sorts of matters!

Thanks for your help!

6
  • 3
    ELB won't restart unhealthy instances by default. You need to setup an auto scaling group for that to occur (you can do that in such a way that it uses the health check, and holds a constant number of instances (maximum = minimum = 1))
    – cyberx86
    Jul 23, 2013 at 21:18
  • 1
    Should have mentioned - ELB isn't technically required in this setup - auto scaling will do the job on its own. What ELB does do for you is provide a DNS address you can access your instance(s) by (and also some sort of error message when a backend is unavailable). (With auto scaling on its own, you would need to re-associate your elastic IP with the new instance when it launches (which can be scripted)).
    – cyberx86
    Jul 23, 2013 at 22:50
  • Ah, rats. But autoscaling requires you to use CloudFlare, no? I'd rather not get involved in that. Is there any way to make it reboot on being unresponsive without using CloudFlare? (Or running another instance, or relying on an external script, etc.)
    – nucleon
    Jul 23, 2013 at 23:04
  • 2
    CloudFlare is not an AWS service (it is a CDN; Amazon's CDN is CloudFront - you don't need that either. What you need is CloudWatch). Autoscaling policies will return you an ARN that you can trigger with a Cloudwatch Alarm (or an ELB health check). Set the --alarm-actions to match the ARN. (If you setup an Unhealthy alarm through ELB, it actually sets up a Cloudwatch alarm). The free tier does cover both Cloudwatch and a few alarms.
    – cyberx86
    Jul 23, 2013 at 23:36
  • 2
    Thanks, I will check it out! (Cloud Flares, Fronts, Watches, oh my!)
    – nucleon
    Jul 24, 2013 at 1:10

1 Answer 1

9

Amazon's Elastic Load Balancer (ELB) distributes requests to healthy instances that have been assigned to it. It does not restart or modify those instances (or their number). It determines 'healthy' instances via a health check - typically polling a given location.

What you are asking for is to 'maintain 1 healthy instance' - that is an auto scaling task. Auto scaling will allow you to define a group of instances (typically including an AMI to launch, the instance type, one or more availability zones to launch the instances in, and the number of instances to maintain (minimum/maximum)), as well as policies by which to scale up and down with. An autoscaling policy returns an ARN (Amazon Resource Name - a reference to a resource).

Once you have your auto scaling group setup, all you need to do is trigger your scaling policies when an instance becomes unhealthy. If you look closely at the health check that you setup with ELB, you will notice that you can setup an alarm - and that alarm is actually a Cloudwatch alarm.

You can setup your own Cloudwatch alarms, or set them up through ELB's health check - just specify the --alarm-actions to trigger the auto-scaling ARN when your unhealthy node criteria is met.

ELB isn't technically required in this setup - auto scaling will do the job on its own. What ELB does do for you is provide a DNS address you can access your instance(s) by (and also some sort of error message when a backend is unavailable). (With auto scaling on its own, you would need to re-associate your elastic IP with the new instance when it launches (which can be scripted)).

Finally, just to clarify: CloudFlare is not an AWS service - it is a CDN (and is somewhat well known for mitigating DDoS attacks). Amazon's equivalent service is CloudFront - you don't need either of them for restarting instances. What you do need is CloudWatch - Amazon's monitoring service). The free tier does cover both Cloudwatch and a few alarms.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .