Otto Mixa
Otto Mixa

Reputation: 178

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

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?

Upvotes: 3

Views: 2342

Answers (2)

Max Desiatov
Max Desiatov

Reputation: 5565

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.

Upvotes: 0

Samuel Karp
Samuel Karp

Reputation: 4682

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.

Upvotes: 1

Related Questions