简体   繁体   English

如何设置 ECS 服务最小和最大任务

[英]How to set ECS Service minimum & maximum tasks

How can I set the minimum and maximum number of tasks of an ECS Service through an API call?如何通过API调用设置ECS服务的最小和最大任务数? 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?我知道您可以通过以下 api 设置所需的任务数,但我没有看到任何设置最小和最大任务的地方? Am I missing something?我错过了什么吗? I am using the PHP API, but any insights here will help.我正在使用 PHP API,但这里的任何见解都会有所帮助。

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

My understanding is that minimum and maximum can only be set with Auto Scaling policies for ECS services.我的理解是,只能使用 ECS 服务的 Auto Scaling 策略设置最小值和最大值。 https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-auto-scaling.html . 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.服务 Auto Scaling 是通过 Amazon ECS、CloudWatch 和 Application Auto Scaling API 的组合实现的。

In your case, just using Application AutoScaling API, registerScalableTarget method call should be enough.在您的情况下,只需使用 Application AutoScaling API, registerScalableTarget 方法调用就足够了。 Here is Example.这是示例。

https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.ApplicationAutoScaling.ApplicationAutoScalingClient.html 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
]);

For those looking for a CLI example,对于那些寻找 CLI 示例的人,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM