Post

13. Auto Scaling Groups

13. Auto Scaling Groups

Template


Prerequisites


1. Auto Scaling Groups

"aws-ec2-0"

Auto Scaling Group is a core service for building scalable systems in AWS. It enables Automatic scaling and self-healing of EC2 instances

1
Launch Template β†’ Auto Scaling Group β†’ EC2 Instances

Auto Scaling Group (ASG) is:

  • A logical group of EC2 instances
  • Managed automatically by AWS

πŸ‘‰ It ensures:

  • The correct number of instances
  • High availability
  • Automatic recovery
1
2
3
4
5
6
7
8
Internet
   ↓
[ Load Balancer ]
   ↓
[ Auto Scaling Group ]
   β”œβ”€β”€ EC2 (AZ-a)
   β”œβ”€β”€ EC2 (AZ-b)
   └── EC2 (AZ-c)

1-1. Behavior

ASG maintains system stability automatically

  • If instances < desired β†’ create new ones
  • If instances > desired β†’ terminate extra ones
  • If instance fails β†’ replace automatically
1
Instance crashed β†’ ASG detects β†’ new instance launched

1-2. Scaling Types

Manual Scaling
  • Change desired capacity manually
Dynamic Scaling ⭐
  • Based on metrics (CPU, traffic)

πŸ‘‰ Example:

  • CPU > 70% β†’ scale out
  • CPU < 30% β†’ scale in
Scheduled Scaling
  • Based on time

πŸ‘‰ Example:

  • Increase capacity during business hours

1-3. Multi-AZ Deployment

ASG can span multiple Availability Zones:

1
2
3
AZ-a β†’ EC2
AZ-b β†’ EC2
AZ-c β†’ EC2

πŸ‘‰ Benefits:

  • High availability
  • Fault tolerance

2. Components of Template

2-1. Launch Template

  • Defines how instances are created
  • Includes AMI, instance type, network, etc.

2-2. Desired Capacity

  • Number of instances you want

2-3. Minimum / Maximum Size

  • Min β†’ lower bound
  • Max β†’ upper bound

3. How to create Template

3-1. Search EC2

"aws-ec2-0"

3-2. Click Navigation pane β†’ β€œAuto Scaling Groups”

"aws-asg0"

3-3. Click Button β†’ β€œCreate Auto Scaling group”

"aws-asg1"

3-4. Step 1. Choose launch template

"aws-asg2"

3-5. Step 2. Choose instance launch options

"aws-asg3"

3-6. Step 3. Integrate with other services - optional

"aws-asg4"

  1. Load balancing: When we want to apply.
  2. Health Check grace period: Standard of normal or not.

3-7. Step 4. Configure group size and scaling - optional

"aws-asg5" "aws-asg6"

3-7. Step 5. Add notifications - optional

"aws-asg7"

3-8. Step 6. Add tags - optional

"aws-asg8"

3-9. Check Activity and Current status

"aws-asg9" "aws-asg10"

4. OPTIONAL


4-1. Load Balancer Integrations

"aws-asg11" "aws-asg12"

4-2. Approach DNS with Load Balancing

"aws-asg13"


4-1. Health Check on ASG

"aws-asg14" "aws-asg15"

  1. Turn on Elastic Load Balancing health checks (Recommended)

Instead of only checking whether the EC2 instance is running, it verifies whether the instance is actually capable of handling incoming traffic.

For example, an EC2 instance may be in a running state, but if the application on it has crashed or is not responding, it will be marked as unhealthy. In this case, the Auto Scaling Group (ASG) will automatically terminate and replace the instance.

Therefore, enabling Elastic Load Balancing health checks is considered a best practice in most production environments.


4-2. Instance Management

"aws-asg16" "aws-asg17"

If the instance become unhealthy, not directly deregistration. According to target groups’s deregistration management, few times later it become deregistration.

  • Components
    • Load Balancing
    • Target Groups
    • Template
This post is licensed under CC BY 4.0 by the author.