Enterprise Cloud Consultancy in The UK and Europe

AWS EC2 Autoscaling

Overview

Amazon EC2 Auto Scaling maintains application availability by automatically adding or removing EC2 instances according to predefined rules. This maintains the health and availability of your application. The benefits of autoscaling are:

  • increased application availability
  • improved fault tolerance
  • lower instance running costs

ASGs defines when and where the autoscaling takes place: the launch template defines the instances

Scaling Policies

  • Manual – manual adjust capacity and autoscaling applies the policy by adding or removing instances
  • Scheduled – set policy based on time – for reliably timed peaks and troughs in workload
  • Dynamic – Simple (add or remove one at a time), Stepped (add or remove multiple instances) and Target Tracking (target CPU usage, queue length, etc based on average performance of the target group)
  • Cooldown Periods – limit frequency of scaling events to prevent thrashing

Scaling Process Settings

  • Launch – add instance (can set to SUSPEND or RESUME)
  • Terminate – remove instance (can set yo SUSPEND or RESUME)
  • AddToLoadBalancer – add to LB
  • AlarmNotification – accept Cloudwatch Alarms
  • AZRebalance – balances instances across multiple AZs
  • HealthCheck – set instance health checks on/off
  • ReplaceUnhealthy – enable replacement of unhealty instance
  • ScheduledActions – enable scheduled actions
  • Standby – InService or Standby – useful to control maintenance on instances

Lifecycle Hooks

On a scale out event, the instance normally moves from Pending to InService. If a custom hook is used then the instance moves into a Pending Wait state until either:

  • the state change timeout expires (3600s default)
  • the custom hook action runs the CompleteLifeCycleAction
  • the complete-lifecycle-action command is run

The instance then moves into the InService state

On a scale in event, the instance normally moves from Terminating to Terminating. If a custom hook is used then the instance moves into a Terminating Wait state until either:

  • the state change timeout expires (3600s default)
  • the custom hook action runs the CompleteLifeCycleAction
  • the complete-lifecycle-action command is run

The instance then moves into the Terminated state

Callouts

The custom action can make callouts to SNS or to EventBridge to trigger further actions