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
  • 6
  • 18

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
  • 10,338
  • 1
  • 31
  • 28