Reputation: 3048
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
Upvotes: 8
Views: 8206
Reputation: 215
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
Upvotes: 10
Reputation: 6265
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.
$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
]);
Upvotes: 3