Skip to content

Commit

Permalink
opt-in to automatic ELB deregister when ELB_LIST=all
Browse files Browse the repository at this point in the history
  • Loading branch information
wjordan committed May 12, 2016
1 parent 3e8f7a8 commit c080f2b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions load-balancing/elb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@ To use these scripts in your own application:
1. Copy the `.sh` files in this directory into your application source.
1. Edit your application's `appspec.yml` to run `deregister_from_elb.sh` on the ApplicationStop event,
and `register_with_elb.sh` on the ApplicationStart event.
1. If your instance is not in an Auto Scaling Group,
edit `common_functions.sh` to set `ELB_LIST` to contain the name(s) of the Elastic Load
Balancer(s) your deployment group is a part of. Make sure the entries in ELB_LIST are separated by space.
Alternatively, you can set `ELB_LIST` to `all` to automatically use all load balancers the instance is
registered to.
1. Deploy!

1 change: 1 addition & 0 deletions load-balancing/elb/common_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

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

# Under normal circumstances, you shouldn't need to change anything below this line.
Expand Down
8 changes: 6 additions & 2 deletions load-balancing/elb/deregister_from_elb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ fi

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

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

msg "Checking that user set at least one load balancer"
if test -z "$ELB_LIST"; then
error_exit "Must have at least one load balancer to deregister from"
fi

# Loop through all LBs the user set, and attempt to deregister this instance from them.
for elb in $ELB_LIST; do
msg "Checking validity of load balancer named '$elb'"
Expand Down
8 changes: 6 additions & 2 deletions load-balancing/elb/register_with_elb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ fi

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

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

msg "Checking that user set at least one load balancer"
if test -z "$ELB_LIST"; then
error_exit "Must have at least one load balancer to register to"
fi

# Loop through all LBs the user set, and attempt to register this instance to them.
for elb in $ELB_LIST; do
msg "Checking validity of load balancer named '$elb'"
Expand Down

0 comments on commit c080f2b

Please sign in to comment.