📖 Scenario: You manage a web application running on AWS ECS (Elastic Container Service). To handle varying traffic, you want the ECS service to automatically adjust the number of running tasks.This project guides you to create an ECS service with auto scaling configured to increase or decrease the number of tasks based on CPU usage.
🎯 Goal: Build an ECS service with auto scaling enabled that adjusts the number of tasks between 1 and 4 based on CPU utilization thresholds.
📋 What You'll Learn
Create an ECS cluster named my-ecs-cluster
Create an ECS service named my-ecs-service running a sample task
Configure auto scaling for the ECS service with minimum 1 and maximum 4 tasks
Set a target tracking scaling policy to maintain CPU utilization at 50%
💡 Why This Matters
🌍 Real World
Auto scaling ECS services is common in real applications to save costs and maintain performance during traffic changes.
💼 Career
Cloud engineers and DevOps professionals often configure ECS auto scaling to ensure applications run smoothly and efficiently.
Progress0 / 4 steps
1
Create ECS Cluster
Create an ECS cluster named my-ecs-cluster using AWS CLI syntax.
AWS
Hint
Use the AWS CLI command aws ecs create-cluster with the --cluster-name option.
2
Create ECS Service
Create an ECS service named my-ecs-service in cluster my-ecs-cluster with desired count 1 and a sample task definition sample-task.
AWS
Hint
Use aws ecs create-service with --cluster, --service-name, --task-definition, and --desired-count options.
3
Configure Auto Scaling Target
Create an Application Auto Scaling target for the ECS service my-ecs-service in cluster my-ecs-cluster with minimum capacity 1 and maximum capacity 4.
AWS
Hint
Use aws application-autoscaling register-scalable-target with the correct --resource-id and capacity limits.
4
Create Target Tracking Scaling Policy
Create a target tracking scaling policy named cpu-utilization-policy for the ECS service my-ecs-service in cluster my-ecs-cluster to maintain CPU utilization at 50%.
AWS
Hint
Create a JSON file named policy.json with the target tracking configuration and use it with put-scaling-policy.
Practice
(1/5)
1. What is the main purpose of ECS service auto scaling?
easy
A. Store container logs for analysis
B. Manually start and stop containers
C. Automatically adjust the number of running containers based on demand
D. Create new ECS clusters automatically
Solution
Step 1: Understand ECS service auto scaling function
ECS service auto scaling changes the number of containers automatically to match workload.
Step 2: Compare options to this function
Only Automatically adjust the number of running containers based on demand describes automatic adjustment of container count based on demand.
Final Answer:
Automatically adjust the number of running containers based on demand -> Option C
Quick Check:
Auto scaling adjusts container count = Automatically adjust containers [OK]
Hint: Auto scaling means automatic container count changes [OK]
Common Mistakes:
Confusing auto scaling with manual container management
Thinking auto scaling creates clusters
Believing auto scaling stores logs
2. Which of the following is the correct way to specify a target tracking scaling policy for CPU utilization in ECS service auto scaling?
easy
A. "TargetValue": 50, "PredefinedMetricSpecification": {"PredefinedMetricType": "ECSServiceAverageCPUUtilization"}
B. "TargetValue": "high", "PredefinedMetricSpecification": {"PredefinedMetricType": "CPUUsage"}
C. "TargetValue": 100, "MetricName": "MemoryUtilization"
D. "TargetValue": 30, "PredefinedMetricSpecification": {"PredefinedMetricType": "NetworkIn"}
Solution
Step 1: Identify correct metric type for CPU utilization
The predefined metric for ECS CPU is "ECSServiceAverageCPUUtilization" with a numeric target value.
Step 2: Check option syntax and metric correctness
"TargetValue": 50, "PredefinedMetricSpecification": {"PredefinedMetricType": "ECSServiceAverageCPUUtilization"} uses correct metric type and numeric target value 50, which is valid.
Final Answer:
"TargetValue": 50, "PredefinedMetricSpecification": {"PredefinedMetricType": "ECSServiceAverageCPUUtilization"} -> Option A
What happens when CPU utilization stays at 70% for a long time?
medium
A. The service scales up to 5 containers to reduce CPU load
B. The service scales down to 2 containers to save cost
C. The service keeps running 2 containers without change
D. The service crashes due to high CPU
Solution
Step 1: Understand scaling triggers from CPU target
TargetValue 60 means ECS tries to keep CPU near 60%. If CPU is 70%, it needs more containers.
Step 2: Apply min and max capacity limits
Min is 2, max is 5. Scaling up is allowed up to 5 containers to reduce CPU load.
Final Answer:
The service scales up to 5 containers to reduce CPU load -> Option A
Quick Check:
CPU above target scales up containers = The service scales up to 5 containers to reduce CPU load [OK]
Hint: CPU above target scales up, below scales down [OK]
Common Mistakes:
Thinking service scales down when CPU is high
Ignoring max capacity limit
Assuming service crashes on high CPU
4. You configured ECS service auto scaling but the service never scales out even when CPU is high. What is a likely cause?
medium
A. The service has no load balancer attached
B. The target CPU utilization is set to 100%
C. The ECS cluster has no running tasks
D. The maximum capacity is set equal to the minimum capacity
Solution
Step 1: Analyze scaling limits
If max capacity equals min capacity, no room to scale out exists.
Step 2: Check other options
Target 100% means scaling triggers only at max CPU, but scaling can still happen. No running tasks or load balancer affect service but not scaling limits directly.
Final Answer:
The maximum capacity is set equal to the minimum capacity -> Option D
Quick Check:
Max equals min blocks scaling out = The maximum capacity is set equal to the minimum capacity [OK]
Hint: Max capacity must be greater than min capacity to scale out [OK]
Common Mistakes:
Ignoring max and min capacity settings
Assuming load balancer affects scaling triggers
Confusing target CPU with scaling limits
5. You want to configure ECS service auto scaling to keep container count between 3 and 10, scaling based on memory usage targeting 70%. Which configuration is correct?
hard
A. MinCapacity: 10, MaxCapacity: 3, TargetValue: 70, PredefinedMetricType: ECSServiceAverageMemoryUtilization
B. MinCapacity: 3, MaxCapacity: 10, TargetValue: 70, PredefinedMetricType: ECSServiceAverageMemoryUtilization
C. MinCapacity: 3, MaxCapacity: 10, TargetValue: 70, PredefinedMetricType: ECSServiceAverageCPUUtilization
D. MinCapacity: 3, MaxCapacity: 10, TargetValue: 30, PredefinedMetricType: ECSServiceAverageMemoryUtilization
Solution
Step 1: Set correct min and max container counts
MinCapacity must be less than MaxCapacity, so 3 and 10 is valid, 10 and 3 is invalid.
Step 2: Use correct metric and target value for memory
Memory scaling uses ECSServiceAverageMemoryUtilization with target 70% to trigger scaling.