aws-solutions / instance-scheduler-on-aws

A cross-account and cross-region solution that allows customers to automatically start and stop EC2 and RDS Instances
https://aws.amazon.com/solutions/implementations/instance-scheduler-on-aws/
Apache License 2.0
541 stars 264 forks source link

Stop and start of EC2 part of an ASG #479

Closed francescoterr77 closed 1 year ago

francescoterr77 commented 1 year ago

Description of the problem:

In my environment I have some EC2 that are part of AutoScalingGroups; for those instances the solution is not working, because the ASG terminates the stopped EC2s and starts new ones.

Suggested solution:

I solved the issue implementing 2 lambda functions, one that suspends and the other that resumes ASG processes https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-suspend-resume-processes.html#as-suspend-resume

this way I can suspend the ASG processes, and then the EC2 can be stopped via the tag defined in the "Instance Scheduler" solution. When the EC2 is restarted (again, via the tag defined in the solution), then the other lambda is executed, and the ASG is back to normal behaviour. The lambda functions are quite simple, I would gladly share the code, and my suggestion is to insert them as part of the solution, so that they are implemented as part of the stackset; in my case the executions of the lambdas and the schedule of the solution are just time-synchronized, but I think it could be possible to bind the execution of these lambda functions to the schedule defined in the dynamodb that is part of the solution.

Let me know if you need further information.

Best regards

hearde commented 1 year ago

We don't plan to support scheduling instances that are part of an ASG for the reasons you mentioned. We also don't intend to suspend and resume the ASG processes. However, we are investigating support for scheduling the ASG itself in an upcoming release.