Skip to content

Commit 20f0b81

Browse files
committed
add ALB support
1 parent ada6322 commit 20f0b81

File tree

7 files changed

+801
-0
lines changed

7 files changed

+801
-0
lines changed

load-balancing/elb-v2/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# ALB and ASG lifecycle event scripts
2+
3+
Often when running a web service, you'll have your instances behind a load balancer. But when
4+
deploying new code to these instances, you don't want the load balancer to continue sending customer
5+
traffic to an instance while the deployment is in progress. Lifecycle event scripts give you the
6+
ability to integrate your AWS CodeDeploy deployments with instances that are behind an ALB Target Group or
7+
in an Auto Scaling group. Simply set the name (or names) of the ALB Target Groups your instances are
8+
a part of, set the scripts in the appropriate lifecycle events, and the scripts will take care of
9+
deregistering the instance, waiting for connection draining, and re-registering after the deployment
10+
finishes.
11+
12+
## Requirements
13+
14+
The register and deregister scripts have a couple of dependencies in order to properly interact with
15+
Application Load Balancing and AutoScaling:
16+
17+
1. The [AWS CLI](http://aws.amazon.com/cli/). In order to take advantage of
18+
AutoScaling's Standby feature, the CLI must be at least version 1.3.25. If you
19+
have Python and PIP already installed, the CLI can simply be installed with `pip
20+
install awscli`. Otherwise, follow the [installation instructions](http://docs.aws.amazon.com/cli/latest/userguide/installing.html)
21+
in the CLI's user guide.
22+
1. An instance profile with a policy that allows, at minimum, the following actions:
23+
24+
```
25+
elasticloadbalancing:Describe*
26+
elasticloadbalancing:DeregisterTagets
27+
elasticloadbalancing:RegisterTargets
28+
autoscaling:Describe*
29+
autoscaling:EnterStandby
30+
autoscaling:ExitStandby
31+
autoscaling:UpdateAutoScalingGroup
32+
```
33+
34+
Note: the AWS CodeDeploy Agent requires that an instance profile be attached to all instances that
35+
are to participate in AWS CodeDeploy deployments. For more information on creating an instance
36+
profile for AWS CodeDeploy, see the [Create an IAM Instance Profile for Your Amazon EC2 Instances]()
37+
topic in the documentation.
38+
1. All instances are assumed to already have the AWS CodeDeploy Agent installed.
39+
40+
## Installing the Scripts
41+
42+
To use these scripts in your own application:
43+
44+
1. Install the AWS CLI on all your instances.
45+
1. Update the policies on the EC2 instance profile to allow the above actions.
46+
1. Copy the `.sh` files in this directory into your application source.
47+
1. Edit your application's `appspec.yml` to run `deregister_from_elb.sh` on the ApplicationStop event,
48+
and `register_with_elb.sh` on the ApplicationStart event.
49+
1. Edit `common_functions.sh` to set `TARGET_LIST` to contain the name(s) of the Target Group your deployment group is a part of. Make sure the entries in TARGET_LIST are separated by space.
50+
1. Edit `common_functions.sh` to set `PORT` to the port number your application is running at (if it's different from the default port number set in Target Group)
51+
1. Deploy!

load-balancing/elb-v2/appspec.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 0.0
2+
os: linux
3+
files:
4+
- source: /
5+
destination: /tmp/elb-test
6+
hooks:
7+
ApplicationStop:
8+
- location: deregister_from_elb.sh
9+
- location: stop_httpd.sh
10+
ApplicationStart:
11+
- location: start_httpd.sh
12+
- location: register_with_elb.sh

0 commit comments

Comments
 (0)