Intro
- Regional Service (cannot span multiple regions)
- Supports Multi AZ
- Automatically add or remove instances (scale horizontally) based on the load
- Free (pay for the underlying resources)
- IAM roles attached to an ASG will get assigned to the launched EC2 instances
- ASG can terminate instances marked as unhealthy by an ELB (and hence replace them)
<aside>
💡 If you have an ASG with running instances and you delete the ASG, the instances will be terminated and the ASG will be deleted.
</aside>
Scaling Policies
- Scheduled Scaling
- Scale based on a schedule
- Used when the load pattern is predictable
- Simple Scaling
- Scale to certain size on a CloudWatch alarm
- Ex. when CPU > 90%, then scale to 10 instances
- Step Scaling
- Scale incrementally in steps using CloudWatch alarms
- Ex. when CPU > 70%, then add 2 units and when CPU < 30%, then remove 1 unit
- Specify the instance warmup time to scale faster
- Target Tracking Scaling
- ASG maintains a CloudWatch metric and scale accordingly (automatically creates CW alarms)
- Ex. maintain CPU usage at 40%
- Predictive Scaling
- Historical data is used to predict the load pattern using ML and scale automatically
Launch Configuration & Launch Template
- Defines the following info for ASG
- AMI (Instance Type)
- EC2 User Data
- EBS Volumes
- Security Groups
- SSH Key Pair
- Min / Max / Desired Capacity
- Subnets (where the instances will be created)
- Load Balancer (specify which ELB to attach instances)
- Scaling Policy
- Launch Configuration (legacy)
- Cannot be updated (must be re-created)
- Does not support Spot Instances
- Launch Template (newer)
- Versioned
- Can be updated
- Supports both On-Demand and Spot Instances
- Recommended by AWS