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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ