21

I want to stop EC2 instances after office hours to save costs. How can I do the same with ECS instances? Even if I stop all tasks/services, the instance is still there? Do I stop the EC2 instance directly?

Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
  • Did you get a useful answer? The solutions here so far will 1- kill the running services without letting them stop and 2- constantly trigger placement alarms if you are running as ECS services. – Mike D Oct 19 '18 at 22:12

4 Answers4

33

From EC2 Management Console

  1. Click Auto Scaling Groups from the left menu.
  2. Select the group from the list.
  3. Click edit on the details tab.
  4. Set desired property to '0'.

After clicking save it is all done.

The Auto Scaling Group is smart enough to shut down all instances.

enter image description here

Kerem Baydoğan
  • 10,475
  • 1
  • 43
  • 50
6

You can use the "Scheduled Actions" feature of Auto Scaling Groups. Starts similar to Kerem Baydoğan's answer From EC2 Management Console:

1 Click Auto Scaling Groups from the left menu.

2 Select the group from the list.

3 Select "Scheduled Actions" from the bar that appeared in the lower middle of the screen.

4 Click on create scheduled action

5 Fill the fields as you see fit and notice that under recurrence there is also a cron option for extra flexibility.

Uberhumus
  • 921
  • 1
  • 13
  • 24
4

If you have the cluster set to a minimum number of nodes with an asg. If you turn off the nodes the asg will start another node to bring it up to three minimum number of nodes. You must set the asg to zero nodes.. Then turn off the current nodes.

  • what is 'asg' that you are referring to? – zaitsman Sep 17 '17 at 23:35
  • ASG == Auto Scaling Grouo – Clint Gallon Sep 17 '17 at 23:37
  • when i updated it to 0, the cluster started shutting down my nodes automatically. Are you saying that you need to set it to 0 when we want to shut it down and then back to desired number when we want it up – zaitsman Sep 17 '17 at 23:38
  • 1
    Yes... If your asg is 3... and you attempt to shut down a node... The cluster will think the node is broken or failing health checks and just bring up a new node – Clint Gallon Sep 17 '17 at 23:42
2

Yes, just stop the EC2 instance directly. When you start the instance again during office hours, the ECS agent will make the services start according to their desired value.

We are doing the same thing and it works for us.

Manish Joshi
  • 3,550
  • 2
  • 21
  • 29
  • 1
    Really, is that working for you guys?!! With the autoscaling group and ECS cluster?! – Ronnie Feb 26 '20 at 10:55
  • The question was asked in 2017 and it has no mention of autoscaling group. Yes, the answer I provided in 2017 in response to the question asked was working for us. – Manish Joshi Nov 12 '20 at 07:23