Development Long read Alb
Set up auto scaling

Set up auto scaling

ASG, ALB, and scaling policy.

11 April 2026 21 min read
Share
X in

Introduction

Auto Scaling Group (ASG) automatically adjusts EC2 instance count to demand. Application Load Balancer (ALB) distributes traffic to healthy instances.

Together they provide high availability, fault tolerance, and cost optimization.

This guide covers ASG, launch template, ALB target group, and scaling policy configuration.

Launch Template

Launch Template is the instance config template: AMI, instance type, SG, user data, IAM profile.

ASG uses launch template version; rolling update migrates to new version.

aws ec2 create-launch-template \
  --launch-template-name myapp-lt \
  --launch-template-data '{
    "ImageId": "ami-xxx",
    "InstanceType": "m7g.large",
    "SecurityGroupIds": ["sg-xxx"],
    "IamInstanceProfile": {"Name": "ec2-app-role"}
  }'

Auto Scaling Group

ASG defines min, max, desired capacity. Distributes instances across AZs. Health check can be ALB or EC2.

Instance refresh performs rolling AMI update.

aws autoscaling create-auto-scaling-group \
  --auto-scaling-group-name myapp-asg \
  --launch-template LaunchTemplateName=myapp-lt \
  --min-size 2 --max-size 10 --desired-capacity 2 \
  --vpc-zone-identifier "subnet-aaa,subnet-bbb" \
  --target-group-arns arn:aws:elasticloadbalancing:...

Application Load Balancer

ALB Layer 7 HTTP/HTTPS load balancing. Target group registers instances. Define health check path and interval.

Listener 443 terminates HTTPS with SSL certificate (ACM).

aws elbv2 create-load-balancer \
  --name myapp-alb \
  --subnets subnet-aaa subnet-bbb \
  --security-groups sg-alb

# Health check: /health, interval 30s, healthy threshold 2

Scaling Policy

Target tracking: CPU 50% target. Step scaling: step scale at CPU thresholds. Scheduled scaling: known traffic patterns.

Scale-in cooldown delays instance termination; prevents flapping.

aws autoscaling put-scaling-policy \
  --auto-scaling-group-name myapp-asg \
  --policy-name cpu-target \
  --policy-type TargetTrackingScaling \
  --target-tracking-configuration '{
    "PredefinedMetricSpecification": {
      "PredefinedMetricType": "ASGAverageCPUUtilization"
    },
    "TargetValue": 50.0
  }'

High Availability

Min 2 instances, 2 AZ is mandatory production standard. ALB disables unhealthy instances.

Full stack HA with Multi-AZ RDS and ElastiCache.

Desired capacity'yi manuel değiştirmeyin; scaling policy yönetsin.

Monitoring and Cost

CloudWatch ASG metrics: GroupDesiredCapacity, GroupInServiceInstances. Alarm triggers scale.

Lower min-size at night via scheduled action for cost (dev/staging).

  1. Launch template versiyonla
  2. ALB health check
  3. Target tracking policy
  4. Çok AZ
  5. Instance refresh planı

Conclusion

ASG + ALB is the backbone of modern EC2 deployment. Build elastic resilient architecture with launch template, target tracking, and multi-AZ.

Validate scaling policies with load test; monitor flapping and lag.