Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(aws-elasticloadbalancingv2): support for ALB/NLB #750

Merged
merged 12 commits into from
Sep 26, 2018
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
Loading