Sub topic 17
Application Auto Scaling, Gateway Load Balancer and Cost-Aware Design
This chapter assumes you know EC2 Auto Scaling groups, target tracking policies and target groups from earlier chapters. It adds three things: scaling services other than EC2, the Gateway Load Balancer, and design rules for resilience and cost.
Scaling other services with Application Auto Scaling
Application Auto Scaling is a separate API (application-autoscaling) that applies the same scaling policy ideas to other services. These include ECS services, DynamoDB tables and indexes, Aurora replicas, Lambda provisioned concurrency and SageMaker endpoints.
Each scaling target is identified by three values:
- Service namespace: for example
ecs. - Resource ID: for example
service/web-cluster/web-service. - Scalable dimension: for example
ecs:service:DesiredCount.
You first register the target with minimum and maximum capacity, then attach a policy.
aws application-autoscaling register-scalable-target \
--service-namespace ecs \
--resource-id service/web-cluster/web-service \
--scalable-dimension ecs:service:DesiredCount \
--min-capacity 2 \
--max-capacity 10
aws application-autoscaling put-scaling-policy \
--service-namespace ecs \
--resource-id service/web-cluster/web-service \
--scalable-dimension ecs:service:DesiredCount \
--policy-name cpu-60 \
--policy-type TargetTrackingScaling \
--target-tracking-scaling-policy-configuration file://ecs-config.jsonThe configuration file ecs-config.json holds the target:
{
"TargetValue": 60.0,
"PredefinedMetricSpecification": {
"PredefinedMetricType": "ECSServiceAverageCPUUtilization"
},
"ScaleOutCooldown": 60,
"ScaleInCooldown": 300
}Scale-out is fast and scale-in is slow, so brief dips in load do not remove capacity too early.
Gateway Load Balancer for network appliances
A Gateway Load Balancer (GWLB) sends traffic through a fleet of virtual appliances, such as firewalls or intrusion detection systems. It works at layer 3. It wraps packets in GENEVE (a tunnel protocol) on port 6081 and keeps each flow on the same appliance. Traffic reaches it through Gateway Load Balancer endpoints, which you target from route tables.
Use a GWLB when you must inspect all traffic transparently. Use an ALB or NLB when you only need to distribute requests to your own application.
Designing for resilience and controlling cost
Resilience rules:
- Use subnets in at least two Availability Zones, and set the minimum capacity to at least 2.
- Set the Auto Scaling group health check type to
ELB, so instances that fail load balancer checks are replaced. - Keep instances stateless. Store sessions and data in services such as DynamoDB or ElastiCache.
- Set the deregistration delay to match your longest normal request.
Cost rules:
- Scale on a metric that reflects demand, such as requests per target.
- Add scheduled scaling for predictable peaks and quiet periods.
- Use a mixed instances policy with Spot Instances for fault-tolerant capacity.
- Set a sensible maximum capacity as a spending limit.
- Delete load balancers and groups that no longer receive traffic.
Exercise
Your ECS service scales out correctly but removes tasks within minutes of a traffic dip, causing slow responses when load returns. Which setting do you change, and in which direction?
Show answer
Increase ScaleInCooldown in the target tracking configuration. A longer scale-in cooldown keeps capacity for longer after a dip, while a short ScaleOutCooldown still lets the service add tasks quickly.