Skip to content

Commit c080f2b

Browse files
committed
opt-in to automatic ELB deregister when ELB_LIST=all
1 parent 3e8f7a8 commit c080f2b

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

load-balancing/elb/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,10 @@ To use these scripts in your own application:
4646
1. Copy the `.sh` files in this directory into your application source.
4747
1. Edit your application's `appspec.yml` to run `deregister_from_elb.sh` on the ApplicationStop event,
4848
and `register_with_elb.sh` on the ApplicationStart event.
49+
1. If your instance is not in an Auto Scaling Group,
50+
edit `common_functions.sh` to set `ELB_LIST` to contain the name(s) of the Elastic Load
51+
Balancer(s) your deployment group is a part of. Make sure the entries in ELB_LIST are separated by space.
52+
Alternatively, you can set `ELB_LIST` to `all` to automatically use all load balancers the instance is
53+
registered to.
4954
1. Deploy!
5055

load-balancing/elb/common_functions.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
# ELB_LIST defines which Elastic Load Balancers this instance should be part of.
1717
# The elements in ELB_LIST should be separated by space.
18+
# Set to "all" to automatically find all load balancers the instance is registered to.
1819
ELB_LIST=""
1920

2021
# Under normal circumstances, you shouldn't need to change anything below this line.

load-balancing/elb/deregister_from_elb.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ fi
5050

5151
msg "Instance is not part of an ASG, continuing..."
5252

53-
msg "Checking that user set at least one load balancer"
54-
if test -z "$ELB_LIST"; then
53+
if [ "${ELB_LIST}" = all ]; then
5554
msg "Finding all the ELBs that this instance is registered to"
5655
get_elb_list $INSTANCE_ID
5756
if [ $? != 0 ]; then
@@ -60,6 +59,11 @@ if test -z "$ELB_LIST"; then
6059
echo "$ELB_LIST" > /tmp/elblist
6160
fi
6261

62+
msg "Checking that user set at least one load balancer"
63+
if test -z "$ELB_LIST"; then
64+
error_exit "Must have at least one load balancer to deregister from"
65+
fi
66+
6367
# Loop through all LBs the user set, and attempt to deregister this instance from them.
6468
for elb in $ELB_LIST; do
6569
msg "Checking validity of load balancer named '$elb'"

load-balancing/elb/register_with_elb.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ fi
5050

5151
msg "Instance is not part of an ASG, continuing..."
5252

53-
msg "Checking that user set at least one load balancer"
54-
if test -z "$ELB_LIST"; then
53+
if [ "${ELB_LIST}" = all ]; then
5554
if [ -a /tmp/elblist ]; then
5655
msg "Finding all the ELBs that this instance was previously registered to"
5756
read ELB_LIST < /tmp/elblist
@@ -61,6 +60,11 @@ if test -z "$ELB_LIST"; then
6160
fi
6261
fi
6362

63+
msg "Checking that user set at least one load balancer"
64+
if test -z "$ELB_LIST"; then
65+
error_exit "Must have at least one load balancer to register to"
66+
fi
67+
6468
# Loop through all LBs the user set, and attempt to register this instance to them.
6569
for elb in $ELB_LIST; do
6670
msg "Checking validity of load balancer named '$elb'"

0 commit comments

Comments
 (0)