Autoscaling with python

0

Due to security requirements autoscaling scale out and scale in is not allowed. the requirement is that the instances that are added to the target group and then removed cannot be terminated. The plan is to create EC2 instances and stop the instances. when an instance needs to be added to the target group due to metric being exceeded (CPU over 60%) then the existing instances is started and then added to the target group. then when the metric falls below the CPU metric then the instance is removed from the target group and then stopped.

I have created python script that will start the stopped instance and added the instance to the target group when the metric is exceeded. I have a python script that will remove the instances, decrement the desired capacity, and shutdown the instance when the metric falls below the set metric.

where i am lost is figuring out how to trigger these python scripts to scale out and scale in. I am looking through cloudwatch and don't see anything to help me. the autoscaling group does not have seem to have the setting to just point to a lambda function when scaling out and scaling in.

is this something that just is not doable?

질문됨 2년 전687회 조회
2개 답변
1

If the only requirement is to retain the instances on scale in. You can leverage instance termination protection in auto scaling. This would allow you to take adavantage of all the features of auto scaling, and still retain the instances. https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-instance-termination.html

If you absolutely cannot use auto scaling, you can leverage EventBridge to invoke a Lambda to run your python script that will interact with EC2. https://aws.amazon.com/premiumsupport/knowledge-center/start-stop-lambda-eventbridge/

profile pictureAWS
전문가
Rob_H
답변함 2년 전
0

In CloudWatch, create an Alarm on the Auto Scaling Group metric such as CPUUtilization. For the Notification, create or select an SNS topic. Then subscribe your Lambda function to this topic.

profile pictureAWS
전문가
kentrad
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠