Bharathi Batthula
5 min readJul 4, 2020

--

AWS: Auto Scaling

It is an AWS feature that allows your AWS component needs (EC2 instances fleet) to grow or shrink depending on your workload requirements.

Auto scaling ensures that you have the right number of AWS EC2 instances for your needs at all times.

Auto Scaling helps you save cost by cutting down the number of EC2 instances when not needed, and scaling out to add more instances only when it is required.

Auto Scaling

Components

  • Launch Configuration

It is the configuration template used to create new EC2 instances for the ASG, defines parameters like : Instance family, Instance type, AMI, Key pair, Block devices and Sec groups are parameters defined in the launch configuration.

  • AS Group

Is a logical grouping of EC2 instances

  • Scaling Policy (Plan)

Determines whe/if and how the ASG scales or shrinks (on-demand/Dynamic scaling, Scheduled scaling)

Launch Configuration

It can be created from AWS console or CLI

You can create a launch configuration from scratch, or

You can use an existing/running EC2 instance to create the launch configuration

  • This is provided that the AMI used to launch this instance does still exist in AWS
  • EC2 instance tags, and any additional block store volume created after the instance launch will not be taken into account.

If you want to change your launch configurations, you have to create a new one, make the required changes, and use that with your auto scaling groups.

Auto Scaling Features

AS can be configured from Console, CLI, SDKs and APIs.

Auto Scaling can span Multi-AZs within the same region.Hence, it can be used to create Fault Tolerant designs on AWS.

COST

There is no additional cost for launching AS Groups. You pay for what you use of EC2 instances.

As can grow or shrink your EC2 instance base, according to your needs, hence, can play an important role in Cost Management.

  • It works well with AWS ELB, Cloud Watch, and Cloud Trail
  • AS is compliant with PCI DSS
  • Auto Scaling can NOT span across multiple Regions
  • You can determine which subnets will AS Groups use to launch new instances in each AZ.
  • Auto Scaling always tries to distribute EC2 instance evenly across AZs where it is enabled.
  • If Auto Scaling fails to launch instances in an AZ, it will try in the other AZs Group until it succeeds.

AS- AZ Rebalance

If AS finds that the number of EC2 instances launched by an ASG into subject AZs is not balanced, AS will initiate a Re balancing Activity.

  • The target of the activity would be to reacg an even distribution of instances between AZs.
  • AS does that by launching new EC2 instances in the AZs that have less EC2 instances first then terminating EC2 instances from the AZs that had more EC2 instances.

What can cause an Imbalance of EC2 instances:

  • You manually change the AZs where your AS is in effect.
  • Manually requesting termination of EC2 instances from your ASG.
  • An AZ that didnot have enough EC2 capacity, now has enough capacity and it is one of your ASG AZs.
  • An AZ with Spot instances market price meeting your bid price.

AS Group- Attaching a Running EC2 instance.

Using AWS Console or CLI, You can attach a running state (not stopped or terminated)

  • Instance is in running state (not stopped or terminated)
  • AMI used to launch the instance still exists.
  • Instance is not part of another AS Group.
  • Instance is in the same AZs of the AS Group.

If the existing EC2 instances under the AS group, plus the one to be added, exceed the maximum capacity of the ASG, the request will fail, EC2 instance won’t be added.

AS Group- Detaching EC2 instances

You can manually remove (Detach) EC2 instance from an AS Group using AWS Console or CLI

You can then manage the detached instances independently, or attach it to another AS Group.

When you detach an instance, you have the option to decrement the ASG’s desired capacity

  • If you do not, the AS Group will launch another instance to replace the one detached

ASG — Standby State

You can manually move an instance from an ASG and put it in standby state

  • Instances in Standby are still managed by Auto Scaling
  • Instances in Standby state are charged as normal, In-service, instances
  • Auto Scaling does not perform Health Checks on instances in Standby state
  • You can troubleshoot the instance or make changes ins tandby mode, without having the Auto Scaling consider that as the instance being unhealthy.

Deleting an ASG

When you delete an ASG, its parameters minimum, and desired capacity are all set to Zero, hence, it terminates all its EC2 instances.

If you want to keep the EC2 instances and manage them independently, you can manually detach them first, then delete the ASG.

Adding an ELB to the ASG

You can attach one or more classic ELBs to your existing AS Group

  • The ELB(s) must be in the same region as the AS Group

Once you do this, any EC2 instance existing or added by the AS Group will be automatically registered with the ASG defined ELBs

  • You do not need to register those instance manaully on the ASG defined ELBs
  • The ELB will then become the focal point for any inbound traffic destined to the ASG EC2 instances

Instance and the ELB(s) must be in the same VPC.

AS Group- Registering/De-Registering EC2 instances to ELBs

If an ELB is attached to the AS Group, then the ELB and instance must be in the same VPC, nad are in the smae Region as the AS Group.

Auto Scaling adds the Attached EC2 instances to the ELB(s) defined to the AS Group

  • Once the EC2 instance is added to the AS Group, it will be automatically registered with the ELB(s) defined under the AS Group

If the AS Group had an ELB defined, detcahing the instance will aso de-register it from the ELB

  • If connection draining was enabled under the ELB, Auto Scaling will honor it.

I will continue further about Auto Scaling in my next coming blog. Thank you.

Bharathi.

--

--

Bharathi Batthula

Bharathi is a self driven and purpose-oriented person.The main mission is to create profound change in her career. contact her on bharathi.batthula6@gmail.com