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?

feita há 2 anos687 visualizações
2 Respostas
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
ESPECIALISTA
Rob_H
respondido há 2 anos
  • thank you very much. i will try your suggestion

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
ESPECIALISTA
kentrad
respondido há 2 anos
  • thank you very much i will try your suggestion

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas