6

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

Blane Townsend
  • 2,888
  • 5
  • 41
  • 55

2 Answers2

8

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
Arun A Nayagam
  • 195
  • 2
  • 9
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
]);
Imran
  • 5,542
  • 3
  • 23
  • 46
  • 1
    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? – Blane Townsend Nov 01 '18 at 22:20
  • 1
    @BlaneTownsend I have edited my answer with PHP SDK Example. – Imran Nov 02 '18 at 01:11