asg
Brief Introduction to AWS ASG
Start the session by introducing the concept of Auto Scaling Groups (ASG):
Definition: An ASG in AWS automatically manages the number of EC2 instances according to demand, enabling applications to scale in and out based on set policies.
Components:
Launch Template/Configuration: Blueprint for EC2 instances (AMI, type, security groups, etc.)
Scaling Policies: Rules for adding/removing instances (target tracking, step scaling, schedule-based)
Health Checks: Mechanism to replace unhealthy instances
Load Balancer (optional): Evenly distributes traffic among instances
Desired, Minimum, Maximum Capacity: Controls the flexibility of scaling
Real-Time Practical Scenario
Scenario: “You’re running a web application that experiences increased traffic during business hours and reduced load during nights and weekends.”
Hands-on Lab Steps
Real-World Examples
E-Commerce Sites: Scale up for seasonal sales and scale down post-sale to save cost.
News Portals: Quickly handle surges during breaking news.
SaaS Applications: Match user demand across global time zones.
Best Practices to Share
Always configure health checks (EC2 and ELB) for accurate recovery.
Use launch templates for consistency and versioning.
Test scaling policies periodically.
Enable notifications (SNS) for scaling events.
Capacity
Desired Capacity: The ideal number of EC2 instances you want running in your ASG at any given time. The ASG tries to maintain this number under normal conditions. When scaling activities are triggered (like a scheduled change or CloudWatch alarm), the desired capacity is adjusted up or down.
Minimum Capacity: The lowest number of EC2 instances that your ASG will maintain. The ASG will not terminate instances below this number.
Maximum Capacity: The highest number of EC2 instances that your ASG can launch. No scaling policies or manual actions will increase the group beyond this limit.
Example:
Minimum: 2
Desired: 3
Maximum: 5
Your ASG will launch 3 instances by default, never let the count fall below 2, and never let it increase above 5—no matter what scaling event occurs.
Additional concepts:
Warmup/Cooldown: Settings to manage how quickly scaling actions repeat.
Health Checks: ASG replaces unreachable/unhealthy instances automatically.
Scaling Limits: Set limits on how much your desired capacity can be increased or decreased. The minimum must be ≤ desired, and maximum must be ≥ desired.
Scaling Modes
Manual scaling: Change desired capacity yourself. ASG will not automatically adjust to workload.
Automatic scaling: ASG adjusts instances in response to CloudWatch metrics or scheduled actions.
Automatic scaling policy options:
No scaling policies: ASG remains static at its initial size.
Target tracking scaling policy: Select a CloudWatch metric and target value (e.g., keep average CPU at 50%). ASG adjusts desired capacity to keep the metric near the target.
Step scaling: Define threshold-based actions to respond more aggressively to big metric changes.
Scheduled scaling: Change desired capacity at specific times (e.g., increase at 9 AM, decrease at 9 PM).
Scenario-Based Questions for Students
1. You have a web app that peaks between 6–10 PM daily. How would you configure an ASG to save costs outside peak hours?
Discuss options such as scheduled scaling to lower desired capacity outside peak hours.
2. An ASG is scaling out, but traffic is not evenly distributed. What could be wrong?
Consider load balancer configuration, target group health, or session affinity/misrouting.
3. If the health check type is set to EC2, but the underlying web service fails, will ASG replace the instance? Why or why not?
EC2 health checks only detect instance-level reachability; they won't detect application-level failures unless ELB/health check integration is used.
4. Your ASG doesn’t scale in after load decreases. What checks would you perform?
Check cooldown/warmup settings, CloudWatch alarms, scaling policies, and activity history for pending terminations.
