- Newest
- Most votes
- Most comments
Hi, I guess everything is possible in computers world and your case too. But it will take a lot of effort to do it and will not be a best practice. I have not seen somebody scale ec2's with lambda.
I guess all you need is to scale ec2s based on messages in queue (very easy with sqs) or just created a load balancer or use autoscaling group https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html
Regards Denys
Scaling with EC2 instances with Lambdas is a common pattern. There are a few options available to assist with this. 1/ Leverage Systems Manager to Start/Stop EC2 instances on a schedule. If you want to minimize the cost of EC2 during off hours, say at night and weekends, this is a simple solution. 2/ Cloudwatch events. You can set up CloudWatch events that trigger based upon a cron or usage of EC2. If using cron, that would trigger at a certain interval, say once a day, to run a Lambda that will shut down the EC2 instance. There are several examples you can search online that shows the code for that Lambda. If you want to have more flexibility, using CloudWatch telemetry, such as CPU utilization, to trigger a shutdown, or even start new instances. 3/ An auto-scaling group is a great way to do the same. You will set up the parameters for scale up/scale down, and the auto-scaling group will manage that for you. 4/ If you want to manage the size of all the services as an entire platform, then using containers managed by Fargate can be a solution. --You can combine these solutions to reduce consumption based upon your needs. Let's say you configure an auto-scaling group that will run during your work hours that has a minimum size of 1. At night and weekends, you have a cron that shuts down the auto-scaling group during off hours. An hour or two before work hours, a cron runs to start the auto-scaling group so you have warm instances ready to go.
Relevant content
- asked 6 months ago
- Accepted Answerasked 7 months ago
- I can't use Amazon EC2 Auto Scaling to launch EC2 instances with encrypted AMIs or encrypted volumesAWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a month ago
- AWS OFFICIALUpdated 4 months ago
Thanks Denys, for helping me out.
As you have mentioned, it is not best practice. What do you suggest me, as in my usecase probably 80 % of the time there will be no traffic, so I want to use 0 GPU based instance, as minimal which I require will cost at least 1.2 USD/hr. And with EC2 Auto Scaling probably we cannot scale down to 0, so how should I approach it?
Thanks Regards