# Should I stop or terminate ec2 instances to save money overnight?

**URL:** <https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678>\
**Category:** AWS Compute Discussion\
**Tags:** lambda, ecs, ec2\
**Created:** [April 19, 2020, 9:11pm UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678 "2020-04-19T21:11:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![07Zulrah](https://awshq.com/letter_avatar_proxy/v4/letter/0/f4b2a3/32.png) [@07Zulrah](https://awshq.com/u/07Zulrah)\
**Post date:** [April 19, 2020, 9:11pm UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/1 "2020-04-19T21:11:15Z")

</div>

Hi,  
We have dev ec2 instances where containers are deployed with ecs. The instances are using autoscalling groups. I wrote the lambda function that sets asg capacity to 0 in the evening and back to 1 in the morning. However, I’m thinking is it a good approach or would it be better to simply suspend autoscalligh healthchecks and stop instances?

Edit: sorry for poor english I was typing on my phone

---

<div class="post-metadata">

**Author:** ![xinehp](https://awshq.com/letter_avatar_proxy/v4/letter/x/d2c977/32.png) [@xinehp](https://awshq.com/u/xinehp)\
**Post date:** [April 19, 2020, 9:16pm UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/2 "2020-04-19T21:16:04Z")

</div>

You could also look at running your containers on fargate instead of managing EC2 infrastructure yourself.

With fargate, you can set the minimum scale to zero.

You could then write a lambda to raise that during testing hours.

---

<div class="post-metadata">

**Author:** ![nanoluka](https://awshq.com/letter_avatar_proxy/v4/letter/n/ec9cab/32.png) [@nanoluka](https://awshq.com/u/nanoluka)\
**Post date:** [April 19, 2020, 9:16pm UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/3 "2020-04-19T21:16:05Z")

</div>

If you terminate your instance, it’s gone - you can’t get it back (unless you made an AMI image or a volume snapshot).

Shutting it down, does allow you to turn it back on in the same state the next day. However, the mere existence of it costs, far less when it’s not running, but still you pay for the storage you use it.

So it’s a bit hard to generalize, but in most cases don’t terminate your instance every day only to launch it next day. Just make sure to shut it down when you finish and you are able to continue where you left off. That would be a personal opinion based on my own experience, if course - your case might be different.

---

<div class="post-metadata">

**Author:** ![hipyhop](https://awshq.com/letter_avatar_proxy/v4/letter/h/85f322/32.png) [@hipyhop](https://awshq.com/u/hipyhop)\
**Post date:** [April 19, 2020, 9:23pm UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/4 "2020-04-19T21:23:10Z")

</div>

Stopping instances will definitely save money.

Ec2 also supports hibernating which is a quicker method of stopping/starting.

However I would really recommend scaling your ASG down to 0 and terminating the instances and relaunching them next day. This will test that your infrastructure is configured correctly and will survive an instance failure in the future.

Treat your instances like cattle:  
[https://medium.com/@Joachim8675309/devops-concepts-pets-vs-cattle-2380b5aab313](https://medium.com/@Joachim8675309/devops-concepts-pets-vs-cattle-2380b5aab313)

---

<div class="post-metadata">

**Author:** ![yarenSC](https://awshq.com/letter_avatar_proxy/v4/letter/y/50afbb/32.png) [@yarenSC](https://awshq.com/u/yarenSC)\
**Post date:** [April 19, 2020, 10:02pm UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/5 "2020-04-19T22:02:15Z")

</div>

> [@xinehp](#):
>
> You could also look at running your containers on fargate instead of managing EC2 infrastructure yourself. With fargate, you can set the minimum scale to zero. You could then write a lambda to raise that during testing …

if the Fargate service was registered as an AutoScaling target, then using scheduled scaling would be simpler:  
[https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-scheduled-scaling.html](https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-scheduled-scaling.html)

---

<div class="post-metadata">

**Author:** ![yarenSC](https://awshq.com/letter_avatar_proxy/v4/letter/y/50afbb/32.png) [@yarenSC](https://awshq.com/u/yarenSC)\
**Post date:** [April 19, 2020, 10:06pm UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/6 "2020-04-19T22:06:11Z")

</div>

If you stop them, you’ll still be paying for EBS overnight. Unless they take a really long time to startup, I’d just set scheduled scaling on the ASG and service each night/morning. Keep in mind that scheduled scaling is UTC based if you have daylight savings or some other type of time change where you live

---

<div class="post-metadata">

**Author:** ![asantos6](https://awshq.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@asantos6](https://awshq.com/u/asantos6)\
**Post date:** [April 19, 2020, 10:13pm UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/7 "2020-04-19T22:13:27Z")

</div>

[https://aws.amazon.com/solutions/implementations/instance-scheduler/](https://aws.amazon.com/solutions/implementations/instance-scheduler/)

---

<div class="post-metadata">

**Author:** ![Seiryth](https://awshq.com/letter_avatar_proxy/v4/letter/s/43a26b/32.png) [@Seiryth](https://awshq.com/u/Seiryth)\
**Post date:** [April 19, 2020, 10:50pm UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/8 "2020-04-19T22:50:10Z")

</div>

> [@asantos6](#):
>
> [https://aws.amazon.com/solutions/implementations/instance-scheduler/](https://aws.amazon.com/solutions/implementations/instance-scheduler/)

Implement this. It works wonderfully.

---

<div class="post-metadata">

**Author:** ![kautica0](https://awshq.com/letter_avatar_proxy/v4/letter/k/48db29/32.png) [@kautica0](https://awshq.com/u/kautica0)\
**Post date:** [April 19, 2020, 11:08pm UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/9 "2020-04-19T23:08:17Z")

</div>

We have a dozen aws accounts some of them dev and there’s so many dev instances running in our environment we must waste a lot of money but I don’t think anyone cares

---

<div class="post-metadata">

**Author:** ![absoluteczech](https://awshq.com/letter_avatar_proxy/v4/letter/a/e0b2c6/32.png) [@absoluteczech](https://awshq.com/u/absoluteczech)\
**Post date:** [April 20, 2020, 1:33am UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/10 "2020-04-20T01:33:08Z")

</div>

> [@kautica0](#):
>
> We have a dozen aws accounts some of them dev and there’s so many dev instances running in our environment we must waste a lot of money but I don’t think anyone cares

Ironic since that’s one of the key benefits of aws is not to waste resources and have low variable costs

---

<div class="post-metadata">

**Author:** ![Hello\_World](https://awshq.com/letter_avatar_proxy/v4/letter/h/ac91a4/32.png) [@Hello\_World](https://awshq.com/u/Hello_World)\
**Post date:** [April 20, 2020, 2:57am UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/11 "2020-04-20T02:57:51Z")

</div>

take a look at tools like cloud custodian and divvy cloud, they give a bit more framework than DIY-ing. all kinds of other neat resource manipulations in there too.

---

<div class="post-metadata">

**Author:** ![ip\_address\_freely](https://awshq.com/letter_avatar_proxy/v4/letter/i/ea666f/32.png) [@ip\_address\_freely](https://awshq.com/u/ip_address_freely)\
**Post date:** [April 20, 2020, 3:37am UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/12 "2020-04-20T03:37:43Z")

</div>

Isn’t there an AWS service for this? It runs them only during certain times?

EDIT: Elastic Load Balancer.

---

<div class="post-metadata">

**Author:** ![\_bazinga](https://awshq.com/letter_avatar_proxy/v4/letter/_/f475e1/32.png) [@\_bazinga](https://awshq.com/u/_bazinga)\
**Post date:** [April 20, 2020, 3:42am UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/13 "2020-04-20T03:42:19Z")

</div>

> [@asantos6](#):
>
> [https://aws.amazon.com/solutions/implementations/instance-scheduler/](https://aws.amazon.com/solutions/implementations/instance-scheduler/)

This

---

<div class="post-metadata">

**Author:** ![pushthepramalot](https://awshq.com/letter_avatar_proxy/v4/letter/p/e0b2c6/32.png) [@pushthepramalot](https://awshq.com/u/pushthepramalot)\
**Post date:** [April 20, 2020, 4:01am UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/14 "2020-04-20T04:01:54Z")

</div>

> [@kautica0](#):
>
> We have a dozen aws accounts some of them dev and there’s so many dev instances running in our environment we must waste a lot of money but I don’t think anyone cares

We install cloud custodian with a policy to stop ec2, RDS and ASG resources at the end of the work day. Teams can exclude resources from being stopped by using a tag. Works great.

---

<div class="post-metadata">

**Author:** ![kulbertinov1](https://awshq.com/letter_avatar_proxy/v4/letter/k/e9bcb4/32.png) [@kulbertinov1](https://awshq.com/u/kulbertinov1)\
**Post date:** [April 20, 2020, 4:27am UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/15 "2020-04-20T04:27:51Z")

</div>

Make a lambda to shut it off for a certain period for you

---

<div class="post-metadata">

**Author:** ![linux\_n00by](https://awshq.com/letter_avatar_proxy/v4/letter/l/65b543/32.png) [@linux\_n00by](https://awshq.com/u/linux_n00by)\
**Post date:** [April 20, 2020, 6:18am UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/16 "2020-04-20T06:18:45Z")

</div>

op, does this mean you control the ec2 autoscale via lambda and not the usual autoscale feature from the console?

---

<div class="post-metadata">

**Author:** ![07Zulrah](https://awshq.com/letter_avatar_proxy/v4/letter/0/f4b2a3/32.png) [@07Zulrah](https://awshq.com/u/07Zulrah)\
**Post date:** [April 20, 2020, 6:42am UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/17 "2020-04-20T06:42:39Z")

</div>

> [@xinehp](#):
>
> You could also look at running your containers on fargate instead of managing EC2 infrastructure yourself. With fargate, you can set the minimum scale to zero. You could then write a lambda to raise that during testing …

Thanks, we use custom logging solution therefore we are not able to use fargate

---

<div class="post-metadata">

**Author:** ![mrsdorothymantooth](https://awshq.com/letter_avatar_proxy/v4/letter/m/db5fbb/32.png) [@mrsdorothymantooth](https://awshq.com/u/mrsdorothymantooth)\
**Post date:** [April 20, 2020, 6:45am UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/18 "2020-04-20T06:45:13Z")

</div>

I’ve implemented this at work. If they live in an auto scaling group add a scheduled scaling actions to the group and scale to 0. For others and RDS install the AWS instance scheduler, you just give the instances a schedule tag that relates to an entry in a DynamoDB table and it will stop and start them for you.

---

<div class="post-metadata">

**Author:** ![07Zulrah](https://awshq.com/letter_avatar_proxy/v4/letter/0/f4b2a3/32.png) [@07Zulrah](https://awshq.com/u/07Zulrah)\
**Post date:** [April 20, 2020, 6:45am UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/19 "2020-04-20T06:45:17Z")

</div>

> [@kautica0](#):
>
> We have a dozen aws accounts some of them dev and there’s so many dev instances running in our environment we must waste a lot of money but I don’t think anyone cares

same happened in all my previous jobs. Now I work in a small team and we’re are the first from the company to move to the cloud. Let’s just say that AWS claims that cloud is save money is not exactly true if you use a lot of mssql, managed kafka and documentdb

---

<div class="post-metadata">

**Author:** ![07Zulrah](https://awshq.com/letter_avatar_proxy/v4/letter/0/f4b2a3/32.png) [@07Zulrah](https://awshq.com/u/07Zulrah)\
**Post date:** [April 20, 2020, 6:47am UTC](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678/20 "2020-04-20T06:47:35Z")

</div>

> [@linux\_n00by](#):
>
> op, does this mean you control the ec2 autoscale via lambda and not the usual autoscale feature from the console?

yes, I implemented a simple lambda function that update the autoscalling group during the night and set min and max capacity to 0.now that I’m thinking about it maybe it’s better to use native console function.

[Next page](https://awshq.com/t/should-i-stop-or-terminate-ec2-instances-to-save-money-overnight/10678.md?page=2)
