Skip to content

Commit

Permalink
feat(aws-elasticloadbalancingv2): support for ALB/NLB (#750)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Adds classes for modeling Application and Network Load
Balancers. AutoScalingGroups now implement the interface that makes
constructs a load balancing target. The breaking change is that Security
Group rule identifiers have been changed in order to make adding rules
more reliable. No code changes are necessary but existing deployments
may experience unexpected changes.
  • Loading branch information
rix0rrr authored Sep 26, 2018
1 parent 6c0e75b commit bd9ee01
Show file tree
Hide file tree
Showing 45 changed files with 5,092 additions and 52 deletions.
25 changes: 23 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
#!/bin/bash
set -euo pipefail

bail="--no-bail"
while [[ "${1:-}" != "" ]]; do
case $1 in
-h|--help)
echo "Usage: build.sh [--bail|-b] [--force|-f]"
exit 1
;;
-b|--bail)
bail="--bail"
;;
-f|--force)
export CDK_BUILD="--force"
;;
*)
echo "Unrecognized parameter: $1"
exit 1
;;
esac
shift
done

if [ ! -d node_modules ]; then
/bin/bash ./install.sh
fi
Expand All @@ -24,10 +45,10 @@ trap "rm -rf $MERKLE_BUILD_CACHE" EXIT

echo "============================================================================================="
echo "building..."
time lerna run --no-bail --stream build || fail
time lerna run $bail --stream build || fail

echo "============================================================================================="
echo "testing..."
lerna run --no-bail --stream test || fail
lerna run $bail --stream test || fail

touch $BUILD_INDICATOR
28 changes: 26 additions & 2 deletions packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ec2 = require('@aws-cdk/aws-ec2');
import elb = require('@aws-cdk/aws-elasticloadbalancing');
import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2');
import iam = require('@aws-cdk/aws-iam');
import sns = require('@aws-cdk/aws-sns');
import cdk = require('@aws-cdk/cdk');
Expand Down Expand Up @@ -136,7 +137,8 @@ export interface AutoScalingGroupProps {
*
* The ASG spans all availability zones.
*/
export class AutoScalingGroup extends cdk.Construct implements elb.ILoadBalancerTarget, ec2.IConnectable {
export class AutoScalingGroup extends cdk.Construct implements elb.ILoadBalancerTarget, ec2.IConnectable,
elbv2.IApplicationLoadBalancerTarget, elbv2.INetworkLoadBalancerTarget {
/**
* The type of OS instances of this fleet are running.
*/
Expand All @@ -157,6 +159,7 @@ export class AutoScalingGroup extends cdk.Construct implements elb.ILoadBalancer
private readonly securityGroup: ec2.SecurityGroupRef;
private readonly securityGroups: ec2.SecurityGroupRef[] = [];
private readonly loadBalancerNames: string[] = [];
private readonly targetGroupArns: string[] = [];

constructor(parent: cdk.Construct, name: string, props: AutoScalingGroupProps) {
super(parent, name);
Expand Down Expand Up @@ -206,7 +209,8 @@ export class AutoScalingGroup extends cdk.Construct implements elb.ILoadBalancer
maxSize: maxSize.toString(),
desiredCapacity: desiredCapacity.toString(),
launchConfigurationName: launchConfig.ref,
loadBalancerNames: new cdk.Token(() => this.loadBalancerNames),
loadBalancerNames: new cdk.Token(() => this.loadBalancerNames.length > 0 ? this.loadBalancerNames : undefined),
targetGroupArns: new cdk.Token(() => this.targetGroupArns.length > 0 ? this.targetGroupArns : undefined),
};

if (props.notificationsTopic) {
Expand Down Expand Up @@ -241,10 +245,30 @@ export class AutoScalingGroup extends cdk.Construct implements elb.ILoadBalancer
this.securityGroups.push(securityGroup);
}

/**
* Attach to a classic load balancer
*/
public attachToClassicLB(loadBalancer: elb.LoadBalancer): void {
this.loadBalancerNames.push(loadBalancer.loadBalancerName);
}

/**
* Attach to ELBv2 Application Target Group
*/
public attachToApplicationTargetGroup(targetGroup: elbv2.ApplicationTargetGroup): elbv2.LoadBalancerTargetProps {
this.targetGroupArns.push(targetGroup.targetGroupArn);
targetGroup.registerConnectable(this);
return { targetType: elbv2.TargetType.SelfRegistering };
}

/**
* Attach to ELBv2 Application Target Group
*/
public attachToNetworkTargetGroup(targetGroup: elbv2.NetworkTargetGroup): elbv2.LoadBalancerTargetProps {
this.targetGroupArns.push(targetGroup.targetGroupArn);
return { targetType: elbv2.TargetType.SelfRegistering };
}

/**
* Add command to the startup script of fleet instances.
* The command must be in the scripting language supported by the fleet's OS (i.e. Linux/Windows).
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-autoscaling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"dependencies": {
"@aws-cdk/aws-ec2": "^0.9.2",
"@aws-cdk/aws-elasticloadbalancing": "^0.9.2",
"@aws-cdk/aws-elasticloadbalancingv2": "^0.9.2",
"@aws-cdk/aws-iam": "^0.9.2",
"@aws-cdk/aws-sns": "^0.9.2",
"@aws-cdk/cdk": "^0.9.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@
}
}
},
"FleetInstanceSecurityGroupPort80LBtofleetDC12B17A": {
"FleetInstanceSecurityGroupfromawscdkec2integLBSecurityGroupDEF4F99A8025E910CB": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
"IpProtocol": "tcp",
Expand Down Expand Up @@ -581,7 +581,7 @@
}
}
},
"LBSecurityGroupPort80LBtofleet0986F2E8": {
"LBSecurityGrouptoawscdkec2integFleetInstanceSecurityGroupB03BE84D80B371C596": {
"Type": "AWS::EC2::SecurityGroupEgress",
"Properties": {
"GroupId": {
Expand Down
Loading

0 comments on commit bd9ee01

Please sign in to comment.