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
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.
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.
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
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
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.
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.
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.