2

Actually I am still a bit confused with aws auto scale up and load balancer

I am wondering if someone can help me clarify if my logic of understand is right and if so, would it be possible to combine the usage of auto-scale up and load balancer?

As for auto-scale up let's say I can setup a cloudalarm that if my main instance reaches to cpu > 90% for a minute then a new instance will spin up and the new instance will share the burden with the main instance to lower the cpu usage. (after spin up, aws will do the rest for us)this is as if I set the setting to spin up 1 instance up to 5 max

If this is correct for my understanding, does the new instance need to have the exactly the same settings of the server? If so, that means I need to create an image of the main instance and each time if I update the main instance I will have to create a new image then change the cloudalarm / auto-scale up to launch the new image right?

  1. If the above is right, is there a better way of doing this? or else, it seems like I have to keep on creating image and change settings if the main instance get changes everyday.

As for load balancer, I read through the documentation and played around. Spin up three instances, registered them all to load balancer. All 3 are healthy, and if I reload the page, it keeps on changing between the three instances. If one instance is down, the other two will be running.

If this is also correct for my understanding, does this mean I need to have 2+ the same instances running and each time when I do deployment I need to do it to all the instances? Wouldn't this be a lot of work if I have lots of servers and want all of them to use load balancer in case the server suddenly becomes unhealthy?

If both of my understanding are correct, is it possible to somehow use auto-scale up with cloudalarm that if somehow main instance is unhealthy create image of the instance then register to the load-balancer?

Sorry for the trouble for the readings, but I do wondering if I am understanding them wrong or I am over thinking and getting myself confused.

Thanks for any advice and help.

Dora
  • 341
  • 1
  • 3
  • 14
  • 1
    First, ask yourself if the added complexity is worth it. Most people don't really *need* auto-scaling - it's a handy tool, but I see lots of folks who could happily run on a pair of servers for the next five years diving deep into it and spending months of time and a bunch of money on it. If you're not running something with highly bursty traffic, you may not need it at all. – ceejayoz Jan 17 '18 at 03:20
  • @ceejayoz I would say `load balancer` is what I need more at this moment since I have tried somehow my instance is just sitting there (didn't have any new code or deployment or any changes) then somehow aws shows an error cannot read the instance. I couldn't back it up too because it couldn't even reach it, this is what made me started looking into load balancer and auto scale up – Dora Jan 17 '18 at 18:30

1 Answers1

4

When you are using Auto Scaling and Load Balancing, you want all your EC2 instances to be identical. So they are all (a) rooted on the same AMI image, and (b) proceed through the same initialization steps to end up with the same code and assets on them. This way, they will all respond the same with the same input from your HTTP client.

To accomplish this, do not attempt to update your EC2 instances manually. When you're scaling up and down, your work will be lost.

When you need to deploy a new version of your code, you should do one (or more) of the following patterns.

Pattern 1:

  • Deploy your code to a "gold" EC2 instance and is not part of your Auto Scaling group.
  • Create an AMI of this "gold" instance.
  • Update your Auto Scaling group to use this new AMI image.
  • Delete old EC2 instances (that use the old AMI) and replace them with new EC2 instance (that use the new AMI)

Pattern 2:

  • Base your Auto Scaling group from a "basic" AMI image
  • When your EC2 instances launch for the first time, they download the source code from some common location (like S3)
  • When you deploy new code, terminate old instances and launch new ones to get the new code

Pattern 3:

  • Do Pattern 2, but
  • Use an automated tool to deploy your new code to your existing EC2 instance rather than terminating them

There are other patterns, but these are some common ones that work.

If you're new to Auto Scaling and Load Balancing, I highly recommend you take a serious look at Elastic Beanstalk. It will manage all of the above for you, making deployments and updates much easier.

Some additional notes:

  • Depending on your application, it may be valid to use 1 EC2 instance behind a Load Balancer. You may not need 2+ instances. You can scale up from 1 instance as your load increases. You simply lose the high availability.
Matt Houser
  • 9,709
  • 1
  • 26
  • 25
  • Thanks for the explanation. I believe pattern one is what I would be thinking of the most but in this case how do the new instances register to load balancer though? or I am thinking of this part wrong, these two shouldn't be mixed together. (I believe I only need load balancer at the moment but reading through the auto scale up just gave me this idea and wonder if this is one of the purpose) *There were quite a few times somehow aws couldn't read my instance when I didn't do anything to the instance this is why I started looking at load balancer – Dora Jan 17 '18 at 18:27
  • 1
    If your Auto Scaling group is configured to use your load balancer, then your instances will automatically register when they start. – Matt Houser Jan 17 '18 at 18:29
  • ah, didn't know about this configuration. is there a huge down time doing it this way? Sorry if I am repeating, just wonna make sure I am getting it right. "gold" instance will be the instance with all the configuration done as if I am using that instance, but only use this instance to create image. auto-scale use that image to let's say `desire` 2 instances. Since load balancer is configured with auto scale up. My root domain just need to configure directing to `load balancer dns name` – Dora Jan 17 '18 at 18:38
  • one quick last question. If I am skipping the auto scale up, and only using the load balancer. `main instance` + `secondary`, I will have to either deploy to both instances or deploy to the `main` image it, launch it, add to load balancer and remove the old `secondary` right? – Dora Jan 17 '18 at 18:41
  • With or without Auto Scaling, you can still use Pattern 1. The difference is that you manually need to replace the EC2 instances. – Matt Houser Jan 17 '18 at 19:36