AWS ECS Auto Scaling for Docker Applications

Automated Scaling of ECS Tasks Based on CPU Utilization

Prev Question Next Question

Question

Your team creates a Docker image for a new web application and deploys it in an AWS ECS cluster.

You want to automatically increase or decrease the desired count of ECS tasks in the ECS service based on the average CPU utilization.

The number of ECS tasks should be adjusted between 3 and 6 and the target value of CPU utilization should be 70

How would you configure this?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Correct Answer - D.

Option A is incorrect because the auto scaling should be configured in the ECS service.

Although you can configure a scaling policy in the Auto Scaling group, the scaling policy cannot adjust the number of ECS tasks.

Option B is incorrect because in the ECS service, you should configure a target tracking scaling policy instead of step scaling policies.

The question mentioned that the value of CPU utilization should be targeted as 70 so that a target tracking scaling policy is needed.

Option C is incorrect because the target tracking scaling policy should be configured in the ECS service instead of the ECS task definition.

Option D is CORRECT because you can add a scaling policy for the ECS service.

The number of ECS tasks will automatically scale based on the target value of the ECSServiceAverageCPUUtilization metric.

Reference:

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-autoscaling-targettracking.html.

The correct answer is D. Configure the auto scaling in the ECS service by adding a target tracking scaling policy based on the ECSServiceAverageCPUUtilization metric.

Explanation: To automatically adjust the number of ECS tasks in the ECS service based on average CPU utilization, we need to configure auto scaling. We can achieve this by adding a target tracking scaling policy to the ECS service.

A. Add a target tracking scaling policy in the Auto Scaling group used by the AWS ECS cluster. Make sure that the policy uses the ECSServiceAverageCPUUtilization metric.

This answer is incorrect as we need to configure auto scaling for the ECS service, not the Auto Scaling group. We need to use the ECSServiceAverageCPUUtilization metric to track the average CPU utilization of the service, not the EC2 instances.

B. In the AWS ECS service console, add two step scaling policies in the Auto Scaling tab. Set up two CloudWatch alarms to scale in and scale out based on the average CPU.

This answer is incorrect because we need to configure target tracking scaling policy, not a step scaling policy. The target tracking policy adjusts the desired count of ECS tasks automatically to maintain the target CPU utilization, while the step scaling policy increases or decreases the number of tasks in fixed steps. Also, the option of adding two CloudWatch alarms is not needed.

C. Set up the target tracking auto scaling in the ECS task definition. Configure the minimum, desired and maximum number of tasks based on the ECSTaskAverageCPUUtilization metric in CloudWatch.

This answer is incorrect because we need to configure auto scaling for the ECS service, not the task definition. Also, the metric used for tracking the CPU utilization of the tasks is ECSTaskCPUUtilization, not ECSTaskAverageCPUUtilization.

D. Configure the auto scaling in the ECS service by adding a target tracking scaling policy based on the ECSServiceAverageCPUUtilization metric.

This is the correct answer. We need to configure auto scaling for the ECS service by adding a target tracking scaling policy based on the ECSServiceAverageCPUUtilization metric. This policy will adjust the desired count of ECS tasks based on the average CPU utilization of the service, ensuring that the CPU utilization stays at the target value of 70%. We can also set the minimum and maximum number of tasks to be between 3 and 6 to ensure that the service scales up or down within that range.

In conclusion, the correct way to configure auto scaling for an ECS service is to add a target tracking scaling policy based on the ECSServiceAverageCPUUtilization metric. This policy will automatically adjust the desired count of ECS tasks to maintain the target CPU utilization, and we can set the minimum and maximum number of tasks to ensure that the service scales up or down within a specific range.