Target tracking is an EC2 Auto Scaling policy that adjusts the number of instances to keep a chosen metric near a target value. Set the target—for example, 70% average CPU utilization—instead of defining scaling steps and alarm thresholds yourself. The policy creates CloudWatch alarms in the background and changes the Auto Scaling group’s desired capacity as load changes. section 17.2.2 section 17.3.1
Choose a metric that responds proportionally when instances are added or removed:
- Use average CPU utilization across an Auto Scaling group, requests per Application Load Balancer target, or average network traffic in or out. section 17.3.1
- Use another CloudWatch metric if instance count affects it proportionally. Request latency does not meet that requirement in this example. section 17.3.1
- Use a different policy when the metric does not fit. SQS queue length does not correlate with the number of workers processing its messages, so the queue-backed example uses step scaling instead. section 17.3.2
Scale a WordPress instance pool by CPU
Place the web servers in an Auto Scaling group behind an Application Load Balancer. In a CloudFormation scaling policy, set PolicyType to TargetTrackingScaling, choose ASGAverageCPUUtilization as the predefined metric, set TargetValue to 70, and set EstimatedInstanceWarmup to 60. The example group has a minimum of two instances and a maximum of four, so scaling remains within those bounds. section 17.3.1
Listing 17.6 Creating a scalable, HA WordPress setup, part 3
ScalingPolicy:
Type: 'AWS::AutoScaling::ScalingPolicy' #1
Properties:
AutoScalingGroupName: !Ref AutoScalingGroup #2
PolicyType: TargetTrackingScaling #3
TargetTrackingConfiguration: #4
PredefinedMetricSpecification: #5
PredefinedMetricType: ASGAverageCPUUtilization #6
TargetValue: 70 #7
EstimatedInstanceWarmup: 60 #8
The CloudFormation listing shows the policy properties and the 70% CPU target together. section 17.3.1
