How does Auto Scaling "place" instances when used with multiple availability zones? - amazon-web-services

Consider the case when an Auto Scaling group is configured to span multiple availability zones (such as in this scenario). When a new Amazon EC2 instance should be added to the scaling group (scale out) based on demand, how does Auto Scaling decide in which availability zone the instance will be placed? The one that has the smaller number of instances?
Thanks for your help.

As you expected, Auto Scaling would indeed select a zone that has the smaller number of instances, section Instance Distribution and Balance Across Multiple Zones within Availability Zones and Regions explains the general algorithm employed by Auto Scaling:
Auto Scaling attempts to distribute instances evenly between the
Availability Zones that are enabled for your Auto Scaling group. Auto
Scaling does this by attempting to launch new instances in the
Availability Zone with the fewest instances. If the attempt fails,
however, Auto Scaling will attempt to launch in other zones until it
succeeds. [emphasis mine]
An Auto Scaling group can also become unbalanced between the zones by various conditions (e.g. active termination of an instance), which can trigger an Auto Scaling rebalancing activity - please check the documentation linked above for more details on this and how edge cases are handled.

Generally its best to scale in such a way that the distribution of instances across zones is even (If you have 3 zones, scaling up would mean adding 3 instances, 1 to each zone). Adding more capacity does not mean traffic will split based on capacity. It will still continue to be round robin.

Related

where new instance will be launched in Auto scaling?

There is set of rules to terminate instance for Auto Scaling when we have multiple AZ.. Same way if we wanted scale up if we have multiple available zones, where exactly instances will be created .. is there any hierarchy?
According to aws docs, if you have multiple availabilty zones for an autoscaling group, aws try to distribute the instance in evenly manner. So if your desired capacity is 8 and there are 4 instances in az-1 and 3 in az-2, the remaining one instance will be created in az-2.
When one Availability Zone becomes unhealthy or unavailable, Amazon EC2 Auto Scaling launches new instances in an unaffected Availability Zone. When the unhealthy Availability Zone returns to a healthy state, Amazon EC2 Auto Scaling automatically redistributes the application instances evenly across all the Availability Zones for your Auto Scaling group. Amazon EC2 Auto Scaling does this by attempting to launch new instances in the Availability Zone with the fewest instances. If the attempt fails, however, Amazon EC2 Auto Scaling attempts to launch in other Availability Zones until it succeeds.
You can read more about this here.

How can I scale EC2 instances in ASG in Zone Sequence

How can I make sure ASG is scaling EC2 instances in a correct Zone sequence, i.e when I scale ASG from 3 instances to 5 instances, it needs to have 2 nodes in Zone-A, 2 in Zone-B and 1 in Zone-C. But in our case, it ends up in 2 nodes in Zone-A, 1 node in Zone-B and 2 nodes in Zone-C.
AWS ASG launches new instances in all Availability zones you enabled for that particular ASG. This is an extract from the official documentation.
Amazon EC2 Auto Scaling attempts to distribute instances evenly between the Availability Zones that are enabled for your Auto Scaling group. Amazon EC2 Auto Scaling does this by attempting to launch new instances in the Availability Zone with the fewest instances. If the attempt fails, however, Amazon EC2 Auto Scaling attempts to launch the instances in another Availability Zone until it succeeds
If you increase the desired capacity to say 9 (and you have 3 AZ's), you'll see there's a high chance there will be 3 instances on each AZ.
There is no way to control which AZ the AutoScaling Group will launch instances in.
The only work around I can think of is that you could make 1 ASG per AZ and then control the desired on your own via a script instead of using a scaling policy. I would recommend trying to make sure your application is as ephemeral as possible without zonal dependencies so that instances can be added in any zone

Can we stop EC2 instance from Auto Scaling Group from AWS

I have an Auto Scaling Group and I want to stop that instance from Auto Scaling Group rather than terminating, Is it possible to do so?
No. From the official definition:
Auto Scaling is a web service designed to launch or terminate Amazon EC2 instances automatically based on user-defined policies, schedules, and health checks.
When scaling-out, new instances are launched into the Auto Scaling group.
When scaling-in, instances are terminated.
Auto Scaling does not start/start instances.
Some benefits of this approach are:
Instances can be launched in different Availability Zones in case there is a failure in a particular AZ
Failed instances can be easily replaced
There is no limit to the number of instances that could be launched (compared to running out of 'stopped' instances)
Launch Configurations can be updated, so any newly-launched instances will use the new configuration (as opposed to recycling old instances)

AWS Auto Scaling Group

As a newbie to AWS concepts, I am trying to understand ASG concept.
a) Does it work per region or per Availability Zones?
b) Do I need to have an ASG for each Availability zone, or it can scale up and down the instances from different AZs on a shared region?
You can have an autoscale group work across availability zones, but not across regions.
Though it is possible to have an ASG in a single AZ, you would certainly want the ASG to be in multiple AZ's, otherwise you have no real fault tolerance in the case where an AZ has problems.

Auto Scaling - Across regions?

I hope you can provide a quick response to my question.
Is it possible to create auto scaling group which spans across regions ? Consider this scenario - Lets say all the availability zones in west are unavailabe. Can we configure auto scaling so that if the instance in US.West are down, create an instance in east zone ?
I dont think it is possible, because we need to specify the region for AWS_AUTO_SCALING_URL while using Command line scripts, which restricts the creation of launch configs, auto scaling group within that region only.
So we can only hope all the AZ's in that region are not down or move to VPC is that right ?
Elastic load balancing and Elastic IP are both region specific, I would assume that auto scaling is region specific and only between the availability zones in that region. The white paper on building fault tolerant applications doesn't explicitly state that you could auto-scale across regions but it does say that you can across zones.
"Auto Scaling can work across multiple Availability Zones in an AWS Region, making it easier to automate increasing and
decreasing of capacity."
I would believe if they supported multi-region, they would explicitly say so.
Thinking about this further, I'm not so sure it's even a good idea to auto-scale across regions. Auto-scale is more geared for a specific tier of your application.
For example, if a region was to go down, you would not want some of your web servers to use services across a slow link to another region (potentially) across the country.
Instead you would want route 53 to route the traffic to an autonomous stack running it's own auto-scaled layers in a separate region.
see this hosting chart everything from ELB down is region specific.
An Auto Scaling group can contain EC2 instances from multiple Availability Zones within the same region. However, an Auto Scaling group can't contain EC2 instances from multiple regions.
Read Note in this AWS Document
EC2 Auto Scaling groups are regional constructs. They can span Availability Zones, but not AWS regions.
PS. AWS Documentation
https://aws.amazon.com/ec2/autoscaling/faqs/