An Auto Scaling group keeps a group of EC2 instances (virtual servers) at a desired count. That count always stays between a minimum and a maximum you set.
It starts new instances from a launch template. The template defines:
- the AMI (the machine image the server boots from)
- the instance type
- the security groups
- the startup script
It spreads the instances across the subnets you give it. Each subnet lives in one AZ (Availability Zone: a separate data centre), so the instances are also spread across AZs.
It replaces instances that fail health checks. By default, it uses EC2 status checks, which only see if the machine itself is broken. You should also turn on ELB health checks. Then an instance is also replaced when the app on it stops answering.
Scaling policies change the desired count as the load changes. An example is target tracking: keep the average CPU, or the request count per target, near a value you choose.
You can attach the group to a load balancer's target group. Then the group registers new instances with the load balancer automatically. It also deregisters instances before it terminates them. It uses connection draining first: the load balancer stops sending new requests and lets open requests finish before the instance goes away.
- It keeps the desired number of instances between the minimum and the maximum.
- A launch template defines what each new instance looks like.
- It spreads instances across AZs through the subnets you give it.
- It replaces unhealthy instances. Turn on ELB health checks so it also catches a broken app.
- It registers and deregisters instances with the target group automatically.