wesupport

Need help?

Our experts have had an average response time of 13.14 minutes in February 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

Configure Amazon ECS Service Auto Scaling on Fargate

by | Aug 22, 2021

Looking for how to configure Amazon ECS Service Auto Scaling on Fargate? We can help you with this!

As a part of our AWS Support Services, we often receive similar requests from our AWS customers.

Today, let’s see the steps followed by our Support Techs to help our customers to configure Amazon ECS Service Auto Scaling on Fargate.

 

 Service Auto Scaling

 
The Service auto-scaling is a combination of the Amazon ECS, CloudWatch, and Application Auto Scaling. It is the ability to increase or decrease the desired count of tasks in our ECS service automatically. Further, we can use CloudWatch metrics to configure the CloudWatch alarms. If the CloudWatch alarms trigger an Auto Scaling policy, then according to the scaling policy the Application Auto Scaling sets the new desired count.

Then, Application Auto Scaling makes the UpdateService API call to Amazon ECS with the new desired count value. The ECS service scheduler launches or shuts down tasks to meet the new desired count. Until the desired count and the running count becomes the same, the scaling activity remains in the InProgress state.
 

Configure Amazon ECS Service Auto Scaling on Fargate

 
Now let’s see the steps to configure Amazon ECS Service Auto Scaling on Fargate:

While creating or updating service in the Amazon ECS console, select the following from the Set Auto Scaling page.

  1. Select Configure Service Auto Scaling to adjust your service’s desired count.

2. Then enter the lowest number of tasks that we wish the Service Auto Scaling to use for the option Minimum number of tasks.

3. Enter the number of tasks that we wish the Service Auto Scaling to use for the option Desired number of tasks.

4. Also enter the highest number of tasks that we wish the Service Auto Scaling to use for the option Maximum number of tasks.

5. Then select ecsAutoscaleRole for the option IAM role for Service Auto Scaling. If this role is not available then select Create new role.

6. Select Auto Scaling Policy in the Automatic task scaling policies section and then proceed with the remaining steps for creating or updating the service.
 

Selecting scaling policy

 
There are two scaling policies and they are target tracking policy and step scaling policy. Based on our requirements we can select any of the policies.
 

Step Scaling Policy

 
For step scaling policies, we create and manage the CloudWatch alarms that trigger the scaling process.

  • We can create or use existing CloudWatch alarms for any metric for step scaling.
  •  

  • We must select scaling actions or step adjustments, like ScalingAdjustment and MetricIntervalUpperBound.
  •  

  • Also, we have to specify the scaling adjustment type as a percentage of the current capacity of the scalable target.
  •  

  • To handle scale-in and scale-out activity, we can increase or decrease the desired task count by creating scaling policies.

 

Target tracking Policy

 

  • We need to set a target value for the specified selected scaling metric. Auto Scaling creates and manages the CloudWatch alarms that trigger the scaling policy and calculates the scaling adjustment according to the metric and the target value.
  •  

  • For target tracking, we can use the ECSServiceAverageCPUUtilization, ECSServiceAverageMemoryUtilization, and ALBRequestCountPerTarget Amazon ECS service metrics.
  •  

  • Also, we must select a scale-out and scale-in cooldown period.

 

Configuration of Service Auto Scaling using the AWS CLI

 
Now let’s see the steps to configure service Auto Scaling using the AWS CLI:

  1. Firstly, we need to register the Fargate service as a scalable target with Application Auto Scaling:
aws application-autoscaling register-scalable-target \
--service-namespace ecs --scalable-dimension ecs:service:DesiredCount \
--resource-id service/your-cluster/your-service-name \
--min-capacity 1 --max-capacity 10 --region us-west-1

2. Then for the scalable target, create a target tracking or step scaling policy:

For Step scaling policy:

  1. At first, create a step scaling policy. For example:
aws application-autoscaling put-scaling-policy \
--service-namespace ecs --scalable-dimension ecs:service:DesiredCount \
--resource-id service/your-cluster/your-service-name \
--policy-name Test-Step-scaling-policy-ScaleOut --policy-type StepScaling \
--step-scaling-policy-configuration '{"AdjustmentType": "ExactCapacity","StepAdjustments": [ { "MetricIntervalLowerBound": 20, "ScalingAdjustment": 10}, { "MetricIntervalLowerBound": 0, "MetricIntervalUpperBound": 20,"ScalingAdjustment": 5}],"Cooldown": 60, "MetricAggregationType": "Average"}'

2. Then we need to associate the scaling policy from step 1 as an alarm action to the new CloudWatch alarm:

aws cloudwatch put-metric-alarm \
--alarm-name Test-ScaleOut --metric-name MemoryUtilization \
--namespace AWS/ECS --statistic Average --period 60 --threshold 60 \
--comparison-operator GreaterThanOrEqualToThreshold --evaluation-periods 1 --datapoints-to-alarm 1 \
--dimensions Name=ClusterName,Value=your-cluster Name=ServiceName,Value=your-service-name --unit Percent \
--alarm-actions "arn:aws:autoscaling:us-west-1:xxxxxxx:scalingPolicy:xxxxxx/Test-Step-scaling-policy-ScaleOut"

3. Finally, create another step scaling policy and CloudWatch alarm for the scale-in activity.

Also note that if the scale-out activity of the service is in progress, then any scale-in activity is allowed only after completing the scale-out activity.

For Target tracking policy:

We need to create a target tracking policy:

aws application-autoscaling put-scaling-policy \
--service-namespace ecs --scalable-dimension ecs:service:DesiredCount \
--resource-id service/<cluster>/<service-name> \
--policy-name Test-target-tracking-scaling-policy --policy-type TargetTrackingScaling \
--target-tracking-scaling-policy-configuration '{ "TargetValue": 75.0, "PredefinedMetricSpecification": {"PredefinedMetricType": "ECSServiceAverageCPUUtilization" }, "ScaleOutCooldown": 60,"ScaleInCooldown": 60}'

While creating the target tracking policy, Application Auto Scaling creates CloudWatch alarms for scaling in and scaling out according to the target value.

[Need help with more AWS queries? We’d be happy to assist]
 

Conclusion

 
To conclude, today we discussed the steps followed by our Support Engineers to help our customers to configure Amazon ECS Service Auto Scaling on Fargate.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Categories

Tags