How to set ECS Service minimum & maximum tasks
Asked Answered
M

2

8

How can I set the minimum and maximum number of tasks of an ECS Service through an API call? I know you can set the desired count of tasks through the following api, but I'm not seeing anywhere to set the minimum and maximum tasks? Am I missing something? I am using the PHP API, but any insights here will help.

https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ecs-2014-11-13.html#updateservice

Magnetostriction answered 1/11, 2018 at 2:37 Comment(0)
H
3

My understanding is that minimum and maximum can only be set with Auto Scaling policies for ECS services. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-auto-scaling.html. You will need to create auto scaling policies to set these.

Service Auto Scaling is made possible by a combination of the Amazon ECS, CloudWatch, and Application Auto Scaling APIs.

In your case, just using Application AutoScaling API, registerScalableTarget method call should be enough. Here is Example.

https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.ApplicationAutoScaling.ApplicationAutoScalingClient.html

$result = $client->registerScalableTarget([
    'MaxCapacity' => 20,
    'MinCapacity' => 2,
    'ResourceId' => 'service/default/sample-webapp', // REQUIRED
    'RoleARN' => 'arn:aws:iam::012345678910:role/ApplicationAutoscalingECSRole',
    'ScalableDimension' => 'ecs:service:DesiredCount', // REQUIRED
    'ServiceNamespace' => 'ecs', // REQUIRED
]);
Hack answered 1/11, 2018 at 2:52 Comment(2)
I have autoscaling working, the issue is I can't figure out how to update the minimum and maximum number of tasks through an API call. I can only update the minimum and maximum through the online console. If you know how to do this can you provide a link to the API call?Magnetostriction
@BlaneTownsend I have edited my answer with PHP SDK Example.Hack
Q
10

For those looking for a CLI example,

aws application-autoscaling \
register-scalable-target \
--service-namespace ecs \
--resource-id service/cluster-name/service-name \
--scalable-dimension ecs:service:DesiredCount \
--min-capacity 2 \
--max-capacity 4
Quincy answered 30/9, 2019 at 11:54 Comment(0)
H
3

My understanding is that minimum and maximum can only be set with Auto Scaling policies for ECS services. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-auto-scaling.html. You will need to create auto scaling policies to set these.

Service Auto Scaling is made possible by a combination of the Amazon ECS, CloudWatch, and Application Auto Scaling APIs.

In your case, just using Application AutoScaling API, registerScalableTarget method call should be enough. Here is Example.

https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.ApplicationAutoScaling.ApplicationAutoScalingClient.html

$result = $client->registerScalableTarget([
    'MaxCapacity' => 20,
    'MinCapacity' => 2,
    'ResourceId' => 'service/default/sample-webapp', // REQUIRED
    'RoleARN' => 'arn:aws:iam::012345678910:role/ApplicationAutoscalingECSRole',
    'ScalableDimension' => 'ecs:service:DesiredCount', // REQUIRED
    'ServiceNamespace' => 'ecs', // REQUIRED
]);
Hack answered 1/11, 2018 at 2:52 Comment(2)
I have autoscaling working, the issue is I can't figure out how to update the minimum and maximum number of tasks through an API call. I can only update the minimum and maximum through the online console. If you know how to do this can you provide a link to the API call?Magnetostriction
@BlaneTownsend I have edited my answer with PHP SDK Example.Hack

© 2022 - 2024 — McMap. All rights reserved.