Skip to content

Commit 4e3cf22

Browse files
committed
Made suspension of processes optional (default to false) and added clarification to README.md
1 parent 2da4b75 commit 4e3cf22

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

load-balancing/elb/README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
Often when running a web service, you'll have your instances behind a load balancer. But when deploying new code to these instances, you don't want the load balancer to continue sending customer traffic to an instance while the deployment is in progress. Lifecycle event scripts give you the ability to integrate your AWS CodeDeploy deployments with instances that are behind an Elastic Load Balancer or in an Auto Scaling group. Simply set the name (or names) of the Elastic Load Balancer your instances are a part of, set the scripts in the appropriate lifecycle events, and the scripts will take care of deregistering the instance, waiting for connection draining, and re-registering after the deployment finishes.
44

5-
*Please note that this scripts will suspend some AutoScaling processes (AZRebalance, AlarmNotification, ScheduledActions and ReplaceUnhealthy) while deploying, in order to avoid wrong interactions.*
6-
75
## Requirements
86

97
The register and deregister scripts have a couple of dependencies in order to properly interact with Elastic Load Balancing and AutoScaling:
@@ -36,4 +34,20 @@ To use these scripts in your own application:
3634
4. 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.
3735
5. 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.
3836
Alternatively, you can set `ELB_LIST` to `_all_` to automatically use all load balancers the instance is registered to, or `_any_` to get the same behaviour as `_all_` but without failing your deployments if the instance is not part of any ASG or ELB. This is more flexible in heterogeneous tag-based Deployment Groups.
39-
6. Deploy!
37+
6. Optionally set up `HANDLE_PROCS=true` in `common_functions.sh`. See note below.
38+
7. Deploy!
39+
40+
## Important notice about handling AutoScaling processes
41+
42+
When using AutoScaling with CodeDeploy you have to consider some edge cases during the deployment time window:
43+
44+
1. If you have a scale up event, the new instance(s) will get the latest successful *Revision*, and not the one you are currently deploying. You will end up with a fleet of mixed revisions.
45+
2. If you have a scale down event, instances are going to be terminated, and your deployment will (probably) fail.
46+
3. If your instances are not balanced accross Availability Zones **and you are** using these scripts, AutoScaling may terminate some instances or create new ones to maintain balance (see [this doc](http://docs.aws.amazon.com/autoscaling/latest/userguide/as-suspend-resume-processes.html#process-types)), interfering with your deployment.
47+
4. If you have the health checks of your AutoScaling Group based off the ELB's ([documentation](http://docs.aws.amazon.com/autoscaling/latest/userguide/healthcheck.html)) **and you are not** using these scripts, then instances will be marked as unhealthy and terminated, interfering with your deployment.
48+
49+
In an effort to solve these cases, the scripts can suspend some AutoScaling processes (AZRebalance, AlarmNotification, ScheduledActions and ReplaceUnhealthy) while deploying, to avoid those events happening in the middle of your deployment. You only have to set up `HANDLE_PROCS=true` in `common_functions.sh`.
50+
51+
A record of the previously (to the start of the deployment) suspended process is kept by the scripts (on each instance), so when finishing the deployment the status of the processes on the AutoScaling Group should be returned to the same status as before. I.e. if AZRebalance was suspended manually it will not be resumed. However, if the scripts don't run (failed deployment) you may end up with stale suspended processes.
52+
53+
**WARNING**: If you are using this functionality you should only use *CodeDepoyDefault.OneAtATime* deployment configuration to ensure a serial execution of the scripts. Concurrent runs are not supported.

load-balancing/elb/common_functions.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ MIN_CLI_VERSION='1.3.25'
4040
# Create a flagfile for each deployment
4141
FLAGFILE="/tmp/asg_codedeploy_flags-$DEPLOYMENT_GROUP_ID-$DEPLOYMENT_ID"
4242

43+
# Handle ASG processes
44+
HANDLE_PROCS=false
45+
4346
# Usage: get_instance_region
4447
#
4548
# Writes to STDOUT the AWS region as known by the local instance.
@@ -224,11 +227,13 @@ autoscaling_enter_standby() {
224227
return 0
225228
fi
226229

227-
msg "Checking ASG ${asg_name} suspended processes"
228-
check_suspended_processes
230+
if [ "$HANDLE_PROCS" = "true" ]; then
231+
msg "Checking ASG ${asg_name} suspended processes"
232+
check_suspended_processes
229233

230-
# Suspend troublesome processes while deploying
231-
suspend_processes
234+
# Suspend troublesome processes while deploying
235+
suspend_processes
236+
fi
232237

233238
msg "Checking to see if ASG ${asg_name} will let us decrease desired capacity"
234239
local min_desired=$($AWS_CLI autoscaling describe-auto-scaling-groups \
@@ -351,8 +356,10 @@ autoscaling_exit_standby() {
351356
msg "Auto scaling group was not decremented previously, not incrementing min value"
352357
fi
353358

354-
# Resume processes, except for the ones suspended before deployment
355-
resume_processes
359+
if [ "$HANDLE_PROCS" = "true" ]; then
360+
# Resume processes, except for the ones suspended before deployment
361+
resume_processes
362+
fi
356363

357364
# Clean up the FLAGFILE
358365
remove_flagfile

0 commit comments

Comments
 (0)