diff --git a/load-balancing/elb/README.md b/load-balancing/elb/README.md index d2cfb95..9ff9137 100644 --- a/load-balancing/elb/README.md +++ b/load-balancing/elb/README.md @@ -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! diff --git a/load-balancing/elb/common_functions.sh b/load-balancing/elb/common_functions.sh index abd74cf..0a004af 100644 --- a/load-balancing/elb/common_functions.sh +++ b/load-balancing/elb/common_functions.sh @@ -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. diff --git a/load-balancing/elb/deregister_from_elb.sh b/load-balancing/elb/deregister_from_elb.sh index 48ce004..59ea1fa 100755 --- a/load-balancing/elb/deregister_from_elb.sh +++ b/load-balancing/elb/deregister_from_elb.sh @@ -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 @@ -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'" diff --git a/load-balancing/elb/register_with_elb.sh b/load-balancing/elb/register_with_elb.sh index c6d2975..9fda0ae 100755 --- a/load-balancing/elb/register_with_elb.sh +++ b/load-balancing/elb/register_with_elb.sh @@ -51,7 +51,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