diff --git a/load-balancing/elb/README.md b/load-balancing/elb/README.md index 69938c4..9ff9137 100644 --- a/load-balancing/elb/README.md +++ b/load-balancing/elb/README.md @@ -46,7 +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. Edit `common_functions.sh` to set `ELB_LIST` to contain the name(s) of the Elastic Load +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 7ee6dbe..0a004af 100644 --- a/load-balancing/elb/common_functions.sh +++ b/load-balancing/elb/common_functions.sh @@ -14,7 +14,8 @@ # permissions and limitations under the License. # ELB_LIST defines which Elastic Load Balancers this instance should be part of. -# The elements in ELB_LIST should be seperated by space. +# 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 c497e57..59ea1fa 100755 --- a/load-balancing/elb/deregister_from_elb.sh +++ b/load-balancing/elb/deregister_from_elb.sh @@ -50,6 +50,15 @@ fi msg "Instance is not part of an ASG, continuing..." +if [ "${ELB_LIST}" = all ]; then + msg "Finding all the ELBs that this instance is registered to" + get_elb_list $INSTANCE_ID + if [ $? != 0 ]; then + error_exit "Must have at least one load balancer to deregister from" + fi + 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" diff --git a/load-balancing/elb/register_with_elb.sh b/load-balancing/elb/register_with_elb.sh index fc4e1f2..5b64db8 100755 --- a/load-balancing/elb/register_with_elb.sh +++ b/load-balancing/elb/register_with_elb.sh @@ -50,6 +50,16 @@ fi msg "Instance is not part of an ASG, continuing..." +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 + rm -f /tmp/elblist + else + error_exit "Must have at least one load balancer to register to" + 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"