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

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

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.

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.

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

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

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

https://aws.amazon.com/solutions/implementations/instance-scheduler/

Implement this. It works wonderfully.

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

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.

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

EDIT: Elastic Load Balancer.

This

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.

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

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

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

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.

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

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.