📜 ⬆️ ⬇️

AWS ELB: Forced disconnection of the instance from the balancer

image Good day!

There was a small but unpleasant moment, when, when scaling a host that is extinguished, just over 30-35 seconds still accepts requests. Naturally, these requests can not work. Therefore, the idea arose before you extinguish the web server, forcibly disconnect the instance from the load balancer.

For this, we need the command line utilities for ELB: aws.amazon.com/developertools/2536 . Extract them into the / opt / aws / elb folder .

Certificates pk - ** and cert - ** put in / opt / aws / keys .
')
The JAVA working folder is / usr / java / latest .

Well, actually the script:
/opt/aws/kick_from_lb.sh
#!/bin/sh export AWS_ELB_HOME="/opt/aws/elb" export PATH=$PATH:$AWS_ELB_HOME/bin export JAVA_HOME=/usr/java/latest export TOOLS_HOME=/opt/aws export EC2_PRIVATE_KEY=$TOOLS_HOME/keys/pk-********88ZVWC3FPEOFWRSFJ.pem export EC2_CERT=$TOOLS_HOME/keys/cert-**********88ZVWC3FPEOFWRSFJ.pem INSTANCE_ID=`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id` elb-deregister-instances-from-lb $1 --instances $INSTANCE_ID 



Now, in the init script of apache, tomcat, nginx, or something else, insert the following line at the beginning of the stop function:

 sh /opt/aws/kick_from_lb.sh $elb_name 

where $ elb_name is the name of your Elastic Load Balancer.

Well that's all. Now, before stopping the web server, the instance will be automatically thrown out from under the balancer and will not accept requests.

Shl. Remember to make all changes to AMI.

Source: https://habr.com/ru/post/147899/


All Articles