Scaling policies (target tracking, step, simple) in AWS - Mini Project: Build & Apply
Create a launch configuration called MyAppLaunchConfig with image ID ami-12345678 and instance type t3.micro. Then create an Auto Scaling Group called MyAppASG using this launch configuration with minimum size 1, maximum size 5, and desired capacity 2.
Use aws_launch_configuration and aws_autoscaling_group resources. Set the exact names and values as specified.
Add a target tracking scaling policy named CPU50Percent to MyAppASG that keeps the average CPU utilization at 50%. Use the predefined metric ASGAverageCPUUtilization.
Use aws_autoscaling_policy with policy_type = "TargetTrackingScaling" and set target_value to 50.
Add a step scaling policy named ScaleUpHighCPU to MyAppASG that increases capacity by 2 when CPU usage exceeds 70%. Use a CloudWatch alarm named HighCPUAlarm that triggers when average CPU is above 70%.
Create a CloudWatch alarm for CPU > 70%. Then create a step scaling policy linked to this alarm that increases capacity by 2.
Add a simple scaling policy named ScaleDownLowCPU to MyAppASG that decreases capacity by 1 when CPU usage falls below 30%. Use a CloudWatch alarm named LowCPUAlarm that triggers when average CPU is below 30%.
Create a CloudWatch alarm for CPU < 30%. Then create a simple scaling policy linked to this alarm that decreases capacity by 1.
Practice
Solution
Step 1: Understand target tracking policy function
Target tracking automatically adjusts resources to keep a metric (like CPU usage) near a set target value.Step 2: Compare with other options
Manual scaling and scheduled scaling do not automatically adjust based on metrics, and disabling scaling is unrelated.Final Answer:
To automatically adjust resources to keep a metric close to a target value -> Option AQuick Check:
Target tracking = automatic metric-based scaling [OK]
- Confusing target tracking with manual scaling
- Thinking scheduled scaling is target tracking
- Assuming target tracking disables scaling
Solution
Step 1: Identify simple scaling policy syntax
Simple scaling uses PolicyType "SimpleScaling" with AdjustmentType and ScalingAdjustment fields.Step 2: Verify JSON options
{"PolicyName": "ScaleOut", "PolicyType": "SimpleScaling", "AdjustmentType": "ChangeInCapacity", "ScalingAdjustment": 2} matches simple scaling syntax; others are for target tracking, step scaling, or scheduled scaling.Final Answer:
{"PolicyName": "ScaleOut", "PolicyType": "SimpleScaling", "AdjustmentType": "ChangeInCapacity", "ScalingAdjustment": 2} -> Option CQuick Check:
Simple scaling = PolicyType "SimpleScaling" [OK]
- Using TargetTrackingScaling type for simple scaling
- Confusing step scaling syntax with simple scaling
- Including schedule fields in simple scaling
{
"PolicyType": "StepScaling",
"StepAdjustments": [
{"MetricIntervalLowerBound": 0, "ScalingAdjustment": 1},
{"MetricIntervalLowerBound": 10, "ScalingAdjustment": 2}
]
}If the metric increases by 12 units, how many instances will be added?
Solution
Step 1: Understand step adjustments
Each step defines scaling for metric intervals. For metric increase of 12, check which intervals apply.Step 2: Find matching step
12 is >=10, so the second step applies with ScalingAdjustment 2.Final Answer:
2 -> Option DQuick Check:
Metric 12 >= 10 -> add 2 instances [OK]
- Adding adjustments from both steps
- Choosing the first step only
- Ignoring metric intervals
Solution
Step 1: Check alarm linkage
Step scaling policies rely on CloudWatch alarms to trigger. If alarms are not linked, no scaling occurs.Step 2: Evaluate other options
Target tracking does not override step scaling; negative adjustments cause scale-in, not no action; no instances means no scaling needed.Final Answer:
The metric alarms are not properly linked to the scaling policy -> Option BQuick Check:
Missing alarm linkage = no scaling trigger [OK]
- Assuming target tracking disables step scaling
- Ignoring alarm configuration
- Confusing negative adjustment with no scaling
Solution
Step 1: Understand target tracking role
Target tracking keeps CPU near 50% automatically adjusting capacity.Step 2: Understand step scaling role
Step scaling defines specific actions when CPU crosses 70% (add 2) or 30% (remove 1).Step 3: Combine policies
Use target tracking for steady state and step scaling for aggressive changes beyond thresholds.Final Answer:
Use a target tracking policy for 50% CPU and step scaling for adding/removing instances at 70% and 30% -> Option AQuick Check:
Target tracking + step scaling = precise control [OK]
- Using only one policy type for all needs
- Confusing scheduled scaling with metric-based scaling
- Ignoring removal scaling actions
Ready to prove it?
Pass the test and this pattern moves unknown
