AWS Auto Scaling and Termination based on CPU Utilization

Terminate Instance from Auto Scaling Group when CPU Utilization is Less than 30%

Prev Question Next Question

Question

You have configured the following AWS services in your organization - Auto Scaling group, Elastic Load Balancer, and EC2 instances.

You have been requested to terminate an instance from the Autoscaling Group when the CPU utilization is less than 30%

How can you achieve this.

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D. E.

Answer - B.

The AWS Documentation mentions the following.

You should have two policies, one for scaling in (terminating instances) and one for scaling out (launching instances), for each event to monitor.

For example, if you want to scale out when the network bandwidth reaches a certain level, create a policy specifying that Auto Scaling should start a certain number of instances to help with your traffic.

But you may also want an accompanying policy to scale in by a certain number when the network bandwidth level goes back down.

For more information on the scaling plans,please see the below link:

http://docs.aws.amazon.com/autoscaling/latest/userguide/scaling_plan.html

To terminate an instance from the Autoscaling Group when the CPU utilization is less than 30%, we can use CloudWatch alarms in conjunction with Auto Scaling group.

CloudWatch is a monitoring service provided by AWS that can monitor and collect metrics, logs, and events from various resources in your AWS environment. CloudWatch alarms can be configured to trigger actions when specific conditions are met, such as when a metric breaches a threshold.

Auto Scaling group is an AWS service that can automatically add or remove EC2 instances based on predefined policies. It can also be integrated with CloudWatch alarms to automatically trigger scaling actions.

Here are the steps to achieve the requirement:

  1. Create a CloudWatch alarm to monitor the CPU utilization of the EC2 instances in the Autoscaling Group. The alarm should trigger when the CPU utilization is less than 30%. This can be achieved by selecting the EC2 instance as the resource, setting the CPU utilization metric, and setting the threshold to 30%.
  2. Configure the alarm to trigger an action when it breaches the threshold. In this case, we want to remove an instance from the Autoscaling Group when the CPU utilization is less than 30%.
  3. Configure the Auto Scaling group to receive the alarm and take action. The Auto Scaling group can be configured to receive the alarm via an SNS topic or by integrating with CloudWatch directly. Once the Auto Scaling group receives the alarm, it can execute a policy to remove an instance from the group.

Option B is the correct answer as it describes the correct way to use CloudWatch alarms and Auto Scaling group to remove an instance from the group. Option A is incorrect because it suggests sending a notification to SQS, which cannot directly remove an instance from the Autoscaling Group. Option C is also incorrect because it suggests sending a notification to the ELB, which also cannot remove an instance from the Autoscaling Group. Option D is incorrect because it suggests that the ELB can remove an instance, which is not true. The ELB can distribute traffic to instances, but it cannot remove instances from the Autoscaling Group. Option E is also incorrect because it suggests manual intervention, which defeats the purpose of automation provided by AWS services.