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

心不动则不痛 提交于 2019-12-12 17:40:54

问题


I'm running AWS ECS cluster with EC2 instances and I want a command to scale up the tasks to 1 running instance and then after some time when I do not need it I want to scale it down to 0. This should destroy the underlying EC2 instance to avoid charges. I'm not using Fargate as it is not in free tier.

what I'm currently using to scale up to one and start running it:

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

what I'm currently using to scale down:

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

Is there an equivalent command only in aws cli without need to use ecs-cli to do the same?


回答1:


Yes, you can call the UpdateService API or use the update-service command.

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

Edit: I misunderstood the question.

You can call the SetDesiredCapacity API or use the set-desired-capacity command to adjust the size of your EC2 auto scaling group.




回答2:


The full command is to scale up/down the cluster is

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

You can get the group name with this command:

aws autoscaling describe-auto-scaling-instances

where the name itself will be in AutoScalingGroupName field of elements in AutoScalingInstances JSON array.



来源:https://stackoverflow.com/questions/50096776/how-to-scale-down-up-containers-in-aws-ecs-cluster-by-command-line-should-i-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!