Elastic Scaling with AWS Autoscaling groups
- Lets do the elastic scaling based on CPU Utilization
- My website works well when CPU Utilization is less than 80%
- Lets start our application with 1 ec2 instance (desired capacity)
- Lets also define the max and min instances
- min: 1
- max: 5
- AWS offers us three ways
- Target Tracking Policy
- Simple Scaling
- Step Scaling
- For now lets use Target Tracking Policy: In this we define the ideal CPU for your application.
- Note for artificial load we will use the stress tool installed on the machine
stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M -v --timeout 100m - For screenshots refer classroom video
- Simple Scaling:
- Works with Cloudwatch alarm
- When an alarm is triggered scale out or in happens depending on configuration
- Cool down period: This is the time after scaling where no other scaling will be allowed
- Step Scaling:
- Similar to simple scaling but no cooldown periods
- AWS also supports Predictive Scaling
Target Tracking Scaling Policy vs. Simple & Step Scaling in AWS Auto Scaling
AWS Auto Scaling supports three types of scaling policies:
1. Simple Scaling – Adds/removes a fixed number of instances per alarm trigger.
2. Step Scaling – Adjusts scaling in steps based on how far the metric deviates from thresholds.
3. Target Tracking Scaling – Automatically adjusts capacity to maintain a target metric value.
What is Target Tracking Scaling Policy?
- Works like a thermostat: Automatically increases or decreases the number of instances to maintain a target metric value.
- AWS continuously monitors the metric and scales dynamically.
- No need to define specific step actions; AWS handles everything.
How It Works
- Define a target metric (e.g., CPU utilization at 50%).
- AWS Auto Scaling adjusts instances dynamically to maintain this target.
- If the metric exceeds the target, AWS adds instances.
- If the metric falls below the target, AWS removes instances.
- AWS handles all calculations, so no manual step configuration is needed.
Key Differences Between Simple, Step, and Target Tracking Scaling
| Feature | Simple Scaling | Step Scaling | Target Tracking Scaling |
|---|---|---|---|
| Scaling Trigger | Fixed threshold | Step-based thresholds | Target-based metric |
| Scaling Adjustment | Adds/removes a fixed number of instances per alarm | Adds/removes instances based on how far the metric deviates | AWS automatically adjusts to maintain the target |
| Response Speed | Slower (cooldown period required) | Faster (no cooldown) | Fastest (reacts dynamically) |
| Configuration Complexity | Simple but rigid | More control, requires tuning | Easiest (AWS auto-manages) |
| Example Use Case | Predictable, slow-changing loads | Large, unpredictable spikes | Maintaining steady performance (e.g., CPU at 50%) |
Example Use Cases for Each Policy
- Simple Scaling – Use when you need basic auto scaling with a fixed instance count change (e.g., “always add 1 instance if CPU > 80%”).
- Step Scaling – Use when different levels of scaling are required based on how much load increases (e.g., “add 1 instance at 70%, 2 at 85%, 3 at 95%”).
- Target Tracking – Use when you want automatic scaling without manual thresholds (e.g., “keep CPU usage at 50% at all times”).
Example: Setting Up Target Tracking in AWS Auto Scaling
Step 1: Define Target Metric
- Go to EC2 Auto Scaling Groups → Select your Auto Scaling Group.
- Click Automatic Scaling → Add a policy.
- Select Target Tracking Scaling.
Step 2: Set Scaling Target
- Choose a metric (e.g., CPU Utilization).
- Set the target value (e.g., 50% CPU).
- AWS automatically adjusts instances to keep CPU close to 50%.
Step 3: Monitor Scaling
- AWS dynamically adds/removes instances to maintain CPU at 50%.
- No manual step configuration is needed.
Final Thoughts: Which One to Use?
| Use Case | Recommended Policy |
|---|---|
| Basic, predictable scaling | Simple Scaling |
| Large, sudden traffic spikes | Step Scaling |
| Fully automated, self-adjusting scaling | Target Tracking Scaling |
If you don’t want to manually define thresholds and steps, Target Tracking Scaling is the best choice.
