Ref: https://learn.cantrill.io/courses/1820301/lectures/41301443
EC2 Auto Scaling Group (ASG) - Key Concepts
Diagram: https://github.com/acantril/aws-sa-associate-saac03/blob/main/1500-HA_and_SCALING/00_LEARNINGAIDS/ASG-1.png
- đź”§Â Logical grouping of EC2 instances
- Automates horizontal scaling and self-healing
- Usually used together with LCs/LTs and ELBs to deliver elastic architectures
- Uses LCs/LTs to provision new instances when scaling out
- âť—Â An ASG has ONE single LC/LT associated to it at any given time
- The LC/LT can be changed, but the previous one then gets disassociated
- All launched instances launched follow the same LC/LT unless changed
- 💡 An ASG defines WHEN & WHERE, its LC/LT defines WHAT
EC2 ASG - X:Y:Z Definition
- ASG behavior can be defined with
X:Y:Z
→ 3 super important values:
X
= Minimum size (MIN) = Minimum number of instances the ASG can have
Y
= Desired Capacity = Number of instances the ASG should have right now
Z
= Maximum size (MAX) = Maximum number of instances the ASG can have
- 💡 e.g.
1:2:4
ASG → MIN=1; DESIRED=2; MAX=4
- 🔧 An ASG's job is to is to keep its running instances at the number specified in the DESIRED capacity → provisions/terminates instances to reach desired capacity
- 💡 Examples:
- If running instances=1 & DESIRED=2 → ASG provisions a new instance
- If running instances=3 & DESIRED=2 → ASG terminates an instance
- DESIRED Capacity can be updated/adjusted:
- Manually (no scaling policy, no intelligence, customer updates themselves)
- ASG will still perform necessary actions when DESIRED is updated manually
- Automatically via Scaling Policy (based on metrics)
- e.g. increase desired capacity if CPU load is high
- âť—Â DESIRED Capacity always adjusted within the MIN-MAX range set by customer!
EC2 ASG - Architecture
Diagram: https://github.com/acantril/aws-sa-associate-saac03/blob/main/1500-HA_and_SCALING/00_LEARNINGAIDS/ASG-2.png
- ASGs are linked to a VPC → ASGs can span multiple subnets & AZs within that VPC
- ASG instances launched in the configured subnets
- By default, ASG attempts to keep the number of instances across subnets as even as possible
- Health monitoring
- Default: EC2 health checks
- If an EC2 instance fails, ASG will replace it → EC2 self-healing (don't confuse with EC2 Auto Recovery feature!)
- Other health checks (e.g. ALB health checks) can be configured
- âť—Â Easy to configure simple EC2 instance recovery
- Configuration:
- Set a LT with desired configuration
- Set ASG to use multiple subnets in different AZs
- Set
1:1:1
to ASG
- 👍 Cheap, simple, and effective HA for one instance (a nice trick)
- Instance will self-recover if it fails
- Instance will self-recover in a different AZ if an AZ fails