Need help?

Our experts have had an average response time of 11.7 minutes in August 2021 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 *

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF