I have an Autoscale Web Application in AWS. When I don't use it, I terminated EC2 instances automatically with Lambda (with Cloudwatch). But I couldn't find an automatic structure to trigger it again.
What I have tried.
- I tried with Cloudwatch but I have to wait after the first request. It's not suitable for my setup.
- I trigger ELB by redirecting the requests coming to port 80 to Lambda and then redirect my main project 443, but it didn't seem very healthy.
If you have other suggestions or services I can use, can you share them?
If you want an immediate response to traffic, then you should not scale to zero instances. Launching or Starting an instance takes time, which probably won't meet your requirement. Therefore, you should always keep a minimum of one instance running at all times.
It is possible to create a warm pool of instances that can be quickly added to the Auto Scaling group. These instances can be kept in a Stopped or Hibernated state to reduce costs, but they will still take time to launch. See: Warm pools for Amazon EC2 Auto Scaling - Amazon EC2 Auto Scaling
The typical pattern is:
A general rule is "Scale-Out quickly, Scale-In slowly":
You mention "I terminated EC2 instances automatically with Lambda (with CloudWatch)". However, EC2 Auto Scaling does not use Lambda functions. Instead, it uses CloudWatch Alarms to monitor metrics and Auto Scaling policies to determine how to respond to Alarms. You can, of course, create your own auto-scaling capabilities using Lambda, but you would miss out on the many capabilities of EC2 Auto Scaling.