2

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?

Otto M.
  • 158
  • 1
  • 10

2 Answers2

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.

Samuel Karp
  • 4,373
  • 22
  • 34
  • I do not have service created currently. Would creation of service create its own CloudWatch metrics causing me to exceed 10 free metrics in free tier? – Otto M. Apr 30 '18 at 18:45
0

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.

Max Desiatov
  • 5,087
  • 3
  • 48
  • 56