Auto Scaling Amazon EC2 and How ? — Day 3

Prabhu Rajendran
Everything at Once
Published in
5 min readAug 28, 2019

In Tradition IT World, there are limited number of servers to handle the application load.when the number of requests increases load on the server also increases, which cause failures and latency in system.

Amazon web service provide Amazon EC2 auto scaling services to overcome this failure.Auto Scaling ensures that Amazon EC2 instances are sufficient to run our application.

What is Amazon EC2 Auto Scaling ? — helps you to ensure that we have the correct number of ec2 instances available to handle the load of you application.

  1. Collection of EC2 instances called Auto Scaling Groups.
  2. Specify the minimum number of instances in each auto scaling groups and auto scaling groups ensures that never goes below the size.
  3. Specify the maximum number of instance in each auto scaling groups and auto scaling groups ensures that never goes above the size.
  4. Specify the desired capacity either when create or after any time — ensures that group has this many instances.
  5. Specify the Scaling Policies- Amazon EC2 Auto scaling can launch or terminate instances as demand on our application increases or decreases.

Auto Scaling Components:

  1. Groups — Each EC2 instances are organized into groups so that they can be treated as logical units for the purpose of scaling and management.(When you create a group we can specify minimum, maximum, desired number of EC2 instances).
  2. Configuration Templates- Our Group uses launch configuration or launch template for its ec2 instances,we can specify information such as AMI ID,instance type, security groups , block device mapping…
  3. Scaling Options — Amazon EC2 Auto scaling provides several ways to scale our auto scaling groups.we can configure scale based on occurrence of specified conditions (dynamic scaling) or on a schedule.

Auto Scaling Life Cycle :- EC2 Instance in Auto Scaling Group has a path or life cycle (that differ from other ec2 instances)

  1. Life cycle starts when Auto Scaling group launches an instance and puts into service.
  2. Life cycle ends when Auto Scaling group terminate the instance, or Auto Scaling group takes the instance out of service and terminates it.
life cycle of auto scaling group ec2 instance

Let see detail about each state whats happening in life cycle.

1.Scale Out: — Directs the Auto Scaling group to launch EC2 instance and attach then to group.

How to attach ec2 instance to group ?

  1. Manually increase the size of group.
  2. create a scaling policy to automatically increase the size of group based on increase in demand.
  3. set up scaling by schedule to increase the size of group.

When a scale out event occurs, the auto scaling group launches the required number (one or more) of ec2 instances, using it launch configuration.

These instances start in PENDING STATE , if we added life cycle hook we can perform custom action, when each instance is fully configured and passes EC2 health check ,it is attached to Auto Scaling group and it enters the In Service State.(The instance is counted against the desired capacity of the auto scaling group).

2. Instance In Service :- Instance remains In service state until one of following state occurs.

a. Scale In event occurs and Amazon Auto Scaling chooses to terminate the instance in order to reduce the size of the Auto Scaling group.

b. put the instance into a Stand By state.

c. Detach the instance from Auto scaling group.

d. Instance fails a required number of health checks, so it is removed from the auto scaling group.

3. Scale In: — Directs the Auto Scaling group to detach EC2 instance from the group and terminate them.

How to detach ec2 instance to group ?

  1. Manually decrease the size of group.
  2. create a scaling policy to automatically decrease the size of group based on decrease in demand.
  3. set up scaling by schedule to decrease the size of group.

It is important that we create a corresponding scale in event for each scale out event that you create.

when a scale in event occurs, the Auto Scaling group detaches one or more instances. The Auto Scaling group uses its termination policy to determine which instances to terminate.Instance that are in process of detaching from auto scaling group and shutting down enter the TERMINATING STATE and cant put back into the service.if we added life cycle hook we can perform custom action, Finally instances are completely terminated and enter the TERMINATED STATE.

4. Attach an Instance —we can attach a running EC2 instance that meets certain criteria to our Auto Scaling group. After the instance is attached, it is managed as part of the Auto Scaling group.

5. Detach an Instance — we can detach an instance from your Auto Scaling group. After the instance is detached, you can manage it separately from the Auto Scaling group or attach it to a different Auto Scaling group.

6. Life cycle Hooks — we can add life cycle hook to our auto scaling group so that we can perform custom actions when instances launch or terminate.

a. Scale Out : (it launches one or more instances) -instances start in the PENDING STATE if we added “autoscaling:EC2_INSTANCE_LAUNCHING” hook to our auto scaling group, instance move from PENDING WAIT STATE, after completion of life cycle action, the instances enter the PENDING: PROCEED state.When the instances are fully configured, they are attached to the Auto Scaling group and they enter the Inservice state.

PENDING -> {PENDING WAIT & PENDING PROCEED STATE} lifecycle action added -> INSERVICE STATE.

b. Scale In : (it detaches one or more instances) -instances are detached in TERMINATING STATE , if we added “autoscaling:EC2_INSTANCE_TERMINATING” hook to our auto scaling group, instance move from TERMINATING WAIT STATE, after completion of life cycle action, the instances enter the TERMINATING: PROCEED state.When the instances are fully terminated, they are detached from Auto Scaling group and they enter the Terminated state.

TERMINATING -> {TERMINATING WAIT & TERMINATING PROCEED STATE }life cycle action added -> TERMINATED .

7. Enter and Exit Stand By :- put any instance that is in an INSERVICE state into a STANDBY state. This enables you to remove the instance from service, troubleshoot or make changes to it, and then put it back into service.

Instances in a STANDBY state continue to be managed by the Auto Scaling group. However, they are not an active part of your application until you put them back into service.

Auto Scaling Limits:

Default Limits

  • Launch configurations per Region: 200
  • Auto Scaling groups per Region: 200

Auto Scaling Group Limits

  • Scaling policies per Auto Scaling group: 50
  • Scheduled actions per Auto Scaling group: 125
  • Lifecycle hooks per Auto Scaling group: 50
  • SNS topics per Auto Scaling group: 10
  • Classic Load Balancers per Auto Scaling group: 50
  • Target groups per Auto Scaling group: 50

Scaling Policy Limits

  • Step adjustments per scaling policy: 20

Yes, we have learnt something about basics in autoscaling and needs of Auto scaling, let see how to do set up , templates configuration in next part.

In case of queries please feel free to comment!.

Thanks for the time.

--

--