I am facing an issue that I have integrated a lambda function for auto starting and stopping of a EC2 instance according to my office hours. However, The issue is that EC2 is on ASG and ASG creates redundant Instance automatically. Could someone please suggest a way to schedule ASG operation to stop and start according to my requirements other than disabling the ASG or removing that instance from ASG.
3 Answers
You can suspend an Auto Scaling group (ASG) according to your EC2 auto-start and stop schedule by using AWS Lambda functions. Lambda functions can be used to trigger the ASG suspend and resume actions at the desired times. You can also use CloudWatch Events to trigger the Lambda functions at the desired times. More details here

- 3,590
- 14
- 33
-
Could you please share any article related to that? for further clarifications? – Mirza Dec 15 '22 at 07:37
-
https://docs.aws.amazon.com/autoscaling/ec2/userguide/lambda-custom-termination-policy.html – Chaitanya Dec 15 '22 at 07:41
I solved this case by using automatic Scaling and creating one schedule to shut down by putting 0s in desired, min and max capacity. And another scheduled to start by putting 1s in desired, min and max capacity(since my requirement is 1 instance at a time) I am not sure if this is the best practice but I solved my issue via this technique.

- 33
- 5
Have you considered scheduled scaling?
To use scheduled scaling, you create scheduled actions. Scheduled actions are performed automatically as a function of date and time. When you create a scheduled action, you specify when the scaling activity should occur and the new desired, minimum, and maximum sizes for the scaling action. You can create scheduled actions that scale one time only or that scale on a recurring schedule.

- 1
- 1