From a2577f8b983acb527611aad60b788133efa93edf Mon Sep 17 00:00:00 2001 From: Sebastian Cruz Date: Fri, 12 Feb 2016 17:48:13 +0000 Subject: [PATCH 1/4] Suspend AZRebalance on ASG --- load-balancing/elb/common_functions.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/load-balancing/elb/common_functions.sh b/load-balancing/elb/common_functions.sh index 7ee6dbe..09230e3 100644 --- a/load-balancing/elb/common_functions.sh +++ b/load-balancing/elb/common_functions.sh @@ -101,6 +101,14 @@ autoscaling_enter_standby() { return 0 fi + msg "Suspending AZRebalance process for ASG ${asg_name}" + $AWS_CLI autoscaling suspend-processes \ + --auto-scaling-group-name "${asg_name}" \ + --scaling-processes AZRebalance + if [ $? != 0 ]; then + msg "Failed to suspend the AZRebalance process for ASG ${asg_name}, but continuing regardless. This may cause issues." + fi + msg "Checking to see if ASG ${asg_name} will let us decrease desired capacity" local min_desired=$($AWS_CLI autoscaling describe-auto-scaling-groups \ --auto-scaling-group-name "${asg_name}" \ @@ -217,6 +225,14 @@ autoscaling_exit_standby() { msg "Auto scaling group was not decremented previously, not incrementing min value" fi + msg "Resuming AZRebalance process for ASG ${asg_name}" + $AWS_CLI autoscaling resume-processes \ + --auto-scaling-group-name "${asg_name}" \ + --scaling-processes AZRebalance + if [ $? != 0 ]; then + msg "Failed to resume the AZRebalance process for ASG ${asg_name}, but continuing regardless. This may cause issues." + fi + return 0 } From 774cc625f5129a74435885657065e530bddc239f Mon Sep 17 00:00:00 2001 From: Sebastian Cruz Date: Sun, 14 Feb 2016 17:58:28 +0000 Subject: [PATCH 2/4] Now checks if AZRebalance was previously set and leaves it like that --- load-balancing/elb/common_functions.sh | 39 ++++++++++++++++++-------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/load-balancing/elb/common_functions.sh b/load-balancing/elb/common_functions.sh index 09230e3..7708b87 100644 --- a/load-balancing/elb/common_functions.sh +++ b/load-balancing/elb/common_functions.sh @@ -101,12 +101,23 @@ autoscaling_enter_standby() { return 0 fi - msg "Suspending AZRebalance process for ASG ${asg_name}" - $AWS_CLI autoscaling suspend-processes \ + msg "Checking to see if ASG ${asg_name} had AZRebalance process suspended previously" + local azrebalance_suspended=$($AWS_CLI autoscaling describe-auto-scaling-groups \ --auto-scaling-group-name "${asg_name}" \ - --scaling-processes AZRebalance - if [ $? != 0 ]; then - msg "Failed to suspend the AZRebalance process for ASG ${asg_name}, but continuing regardless. This may cause issues." + --query 'AutoScalingGroups[].SuspendedProcesses' \ + --output text | grep -c 'AZRebalance') + if [ $azrebalance_suspended -eq 1 ]; then + msg "ASG ${asg_name} had AZRebalance suspended, creating flag file /tmp/azrebalanced" + # Create a "flag" file to denote that the ASG had AZRebalance enabled + touch /tmp/azrebalanced + else + msg "ASG ${asg_name} didn't have AZRebalance suspended, suspending" + $AWS_CLI autoscaling suspend-processes \ + --auto-scaling-group-name "${asg_name}" \ + --scaling-processes AZRebalance + if [ $? != 0 ]; then + msg "Failed to suspend the AZRebalance process for ASG ${asg_name}, but continuing regardless. This may cause issues." + fi fi msg "Checking to see if ASG ${asg_name} will let us decrease desired capacity" @@ -225,12 +236,18 @@ autoscaling_exit_standby() { msg "Auto scaling group was not decremented previously, not incrementing min value" fi - msg "Resuming AZRebalance process for ASG ${asg_name}" - $AWS_CLI autoscaling resume-processes \ - --auto-scaling-group-name "${asg_name}" \ - --scaling-processes AZRebalance - if [ $? != 0 ]; then - msg "Failed to resume the AZRebalance process for ASG ${asg_name}, but continuing regardless. This may cause issues." + if [ -a /tmp/azrebalanced ]; then + msg "ASG ${asg_name} had AZRebalance suspended previously, leaving it suspended" + msg "Removing /tmp/azrebalanced flag file" + rm -f /tmp/azrebalanced + else + msg "Resuming AZRebalance process for ASG ${asg_name}" + $AWS_CLI autoscaling resume-processes \ + --auto-scaling-group-name "${asg_name}" \ + --scaling-processes AZRebalance + if [ $? != 0 ]; then + msg "Failed to resume the AZRebalance process for ASG ${asg_name}, but continuing regardless. This may cause issues." + fi fi return 0 From 43d1c5c332ea1377c5aeb5cc55755c603ef60c72 Mon Sep 17 00:00:00 2001 From: Sebastian Cruz Date: Thu, 14 Apr 2016 16:10:16 +0100 Subject: [PATCH 3/4] Fail the script run if unable to set/unset AZRebalance --- load-balancing/elb/common_functions.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/load-balancing/elb/common_functions.sh b/load-balancing/elb/common_functions.sh index 7708b87..f43f9d5 100644 --- a/load-balancing/elb/common_functions.sh +++ b/load-balancing/elb/common_functions.sh @@ -116,7 +116,8 @@ autoscaling_enter_standby() { --auto-scaling-group-name "${asg_name}" \ --scaling-processes AZRebalance if [ $? != 0 ]; then - msg "Failed to suspend the AZRebalance process for ASG ${asg_name}, but continuing regardless. This may cause issues." + msg "Failed to suspend the AZRebalance process for ASG ${asg_name}. Aborting as this may cause issues." + return 1 fi fi @@ -246,7 +247,8 @@ autoscaling_exit_standby() { --auto-scaling-group-name "${asg_name}" \ --scaling-processes AZRebalance if [ $? != 0 ]; then - msg "Failed to resume the AZRebalance process for ASG ${asg_name}, but continuing regardless. This may cause issues." + msg "Failed to resume the AZRebalance process for ASG ${asg_name}. This may cause issues!" + return 1 fi fi From 40f625768c1eb36e034023119663c638c0819afc Mon Sep 17 00:00:00 2001 From: Sebastian Cruz Date: Thu, 14 Apr 2016 16:16:58 +0100 Subject: [PATCH 4/4] Add needed actions to IAM policy --- load-balancing/elb/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/load-balancing/elb/README.md b/load-balancing/elb/README.md index 69938c4..88b4510 100644 --- a/load-balancing/elb/README.md +++ b/load-balancing/elb/README.md @@ -29,6 +29,8 @@ in the CLI's user guide. autoscaling:EnterStandby autoscaling:ExitStandby autoscaling:UpdateAutoScalingGroup + autoscaling:SuspendProcesses + autoscaling:ResumeProcesses ``` Note: the AWS CodeDeploy Agent requires that an instance profile be attached to all instances that