Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions load-balancing/elb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions load-balancing/elb/common_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ autoscaling_enter_standby() {
return 0
fi

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}" \
--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}. Aborting as this may cause issues."
return 1
fi
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}" \
Expand Down Expand Up @@ -217,6 +237,21 @@ autoscaling_exit_standby() {
msg "Auto scaling group was not decremented previously, not incrementing min value"
fi

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}. This may cause issues!"
return 1
fi
fi

return 0
}

Expand Down