如何通过命令行在aws ecs集群中扩展down/up个容器,我应该使用aws cli还是ecs-cli?

How to scale down/up containers in aws ecs cluster by command line, should I use aws cli or ecs-cli?

我是 运行 带有 EC2 实例的 AWS ECS 集群,我想要一个命令将任务扩展到 1 个 运行 实例,然后在我不需要它的一段时间后我想要将其缩小到 0。这应该会破坏底层 EC2 实例以避免收费。我没有使用 Fargate,因为它不在免费套餐中。

我目前使用什么来扩展到一个并开始 运行 它:

ecs-cli scale --capability-iam --size 1 --cluster myEC2clusterName --region us-east-1
aws ecs run-task --cluster myEC2clusterName --region us-east-1 --task-definition myTaskDefinitionName:1 --count 1

我目前使用的是什么来缩小:

ecs-cli scale --capability-iam --size 0 --cluster myEC2clusterName --region us-east-1

是否只在 aws cli 中有一个等效的命令而不需要使用 ecs-cli 来做同样的事情?

可以,可以调用UpdateService API or use the update-service命令

aws ecs update-service --cluster myEC2clusterName --region us-east-1 --service myServiceName --desired-count 0

编辑:我误解了问题。

您可以调用 SetDesiredCapacity API or use the set-desired-capacity 命令来调整您的 EC2 自动缩放组的大小。

完整命令是扩展 up/down 集群是

aws autoscaling set-desired-capacity --desired-capacity 2 \
  --auto-scaling-group-name <your-group-name>

您可以通过以下命令获取群组名称:

aws autoscaling describe-auto-scaling-instances

名称本身将位于 AutoScalingInstances JSON 数组中元素的 AutoScalingGroupName 字段中。