Skip to content

Commit 8e05d49

Browse files
authoredMay 16, 2019
fix(codedeploy): change the load balancer API in server Deployment Group. (#2548)
BREAKING CHANGE: the type of the `loadBalancer` property in ServerDeploymentGroupProps has been changed. Fixes #2449
1 parent 82c1f10 commit 8e05d49

File tree

17 files changed

+104
-94
lines changed

17 files changed

+104
-94
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
## AWS CodeDeploy Load Balancing API
22

3-
This package contains the abstract API of Load Balancers
4-
as required by the AWS CodeDeploy Construct Library.
5-
6-
You should never need to depend on it directly -
7-
instead, depend on the `aws-codedeploy` package.
3+
This package has been deprecated,
4+
and will be removed in a future release of the Cloud Development Kit.
5+
Please remove if from your dependencies.
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
export * from './load-balancer';

‎packages/@aws-cdk/aws-codedeploy-api/lib/load-balancer.ts

-32
This file was deleted.

‎packages/@aws-cdk/aws-codedeploy-api/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@aws-cdk/aws-codedeploy-api",
33
"version": "0.31.0",
44
"description": "Load Balancer API for AWS CodeDeploy",
5+
"deprecated": "This package is now obsololete, please remove it from your dependencies",
56
"main": "lib/index.js",
67
"types": "lib/index.d.ts",
78
"jsii": {

‎packages/@aws-cdk/aws-codedeploy/README.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,23 @@ const deploymentGroup = codedeploy.ServerDeploymentGroup.import(this, 'ExistingC
9090
You can [specify a load balancer](https://docs.aws.amazon.com/codedeploy/latest/userguide/integrations-aws-elastic-load-balancing.html)
9191
with the `loadBalancer` property when creating a Deployment Group.
9292

93+
`LoadBalancer` is an abstract class with static factory methods that allow you to create instances of it from various sources.
94+
9395
With Classic Elastic Load Balancer, you provide it directly:
9496

9597
```ts
9698
import lb = require('@aws-cdk/aws-elasticloadbalancing');
9799

98100
const elb = new lb.LoadBalancer(this, 'ELB', {
99-
// ...
101+
// ...
100102
});
101103
elb.addTarget(/* ... */);
102104
elb.addListener({
103-
// ...
105+
// ...
104106
});
105107

106108
const deploymentGroup = new codedeploy.ServerDeploymentGroup(this, 'DeploymentGroup', {
107-
loadBalancer: elb,
109+
loadBalancer: codedeploy.LoadBalancer.classic(elb),
108110
});
109111
```
110112

@@ -115,17 +117,17 @@ you provide a Target Group as the load balancer:
115117
import lbv2 = require('@aws-cdk/aws-elasticloadbalancingv2');
116118

117119
const alb = new lbv2.ApplicationLoadBalancer(this, 'ALB', {
118-
// ...
120+
// ...
119121
});
120122
const listener = alb.addListener('Listener', {
121-
// ...
123+
// ...
122124
});
123125
const targetGroup = listener.addTargets('Fleet', {
124-
// ...
126+
// ...
125127
});
126128

127129
const deploymentGroup = new codedeploy.ServerDeploymentGroup(this, 'DeploymentGroup', {
128-
loadBalancer: targetGroup,
130+
loadBalancer: codedeploy.LoadBalancer.application(targetGroup),
129131
});
130132
```
131133

‎packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import autoscaling = require('@aws-cdk/aws-autoscaling');
22
import cloudwatch = require('@aws-cdk/aws-cloudwatch');
3-
import codedeploylb = require('@aws-cdk/aws-codedeploy-api');
43
import ec2 = require('@aws-cdk/aws-ec2');
54
import iam = require('@aws-cdk/aws-iam');
65
import s3 = require('@aws-cdk/aws-s3');
@@ -10,6 +9,7 @@ import { AutoRollbackConfig } from '../rollback-config';
109
import { arnForDeploymentGroup, renderAlarmConfiguration, renderAutoRollbackConfiguration } from '../utils';
1110
import { IServerApplication, ServerApplication } from './application';
1211
import { IServerDeploymentConfig, ServerDeploymentConfig } from './deployment-config';
12+
import { LoadBalancer, LoadBalancerGeneration } from './load-balancer';
1313

1414
export interface IServerDeploymentGroup extends cdk.IResource {
1515
readonly application: IServerApplication;
@@ -190,12 +190,12 @@ export interface ServerDeploymentGroupProps {
190190

191191
/**
192192
* The load balancer to place in front of this Deployment Group.
193-
* Can be either a classic Elastic Load Balancer,
193+
* Can be created from either a classic Elastic Load Balancer,
194194
* or an Application Load Balancer / Network Load Balancer Target Group.
195195
*
196196
* @default the Deployment Group will not have a load balancer defined
197197
*/
198-
readonly loadBalancer?: codedeploylb.ILoadBalancer;
198+
readonly loadBalancer?: LoadBalancer;
199199

200200
/**
201201
* All EC2 instances matching the given set of tags when a deployment occurs will be added to this Deployment Group.
@@ -387,25 +387,23 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupBase {
387387
}
388388
}
389389

390-
private loadBalancerInfo(lbProvider?: codedeploylb.ILoadBalancer):
390+
private loadBalancerInfo(loadBalancer?: LoadBalancer):
391391
CfnDeploymentGroup.LoadBalancerInfoProperty | undefined {
392-
if (!lbProvider) {
392+
if (!loadBalancer) {
393393
return undefined;
394394
}
395395

396-
const lb = lbProvider.asCodeDeployLoadBalancer();
397-
398-
switch (lb.generation) {
399-
case codedeploylb.LoadBalancerGeneration.First:
396+
switch (loadBalancer.generation) {
397+
case LoadBalancerGeneration.FIRST:
400398
return {
401399
elbInfoList: [
402-
{ name: lb.name },
400+
{ name: loadBalancer.name },
403401
],
404402
};
405-
case codedeploylb.LoadBalancerGeneration.Second:
403+
case LoadBalancerGeneration.SECOND:
406404
return {
407405
targetGroupInfoList: [
408-
{ name: lb.name },
406+
{ name: loadBalancer.name },
409407
]
410408
};
411409
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './application';
22
export * from './deployment-config';
33
export * from './deployment-group';
4+
export * from './load-balancer';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import elb = require('@aws-cdk/aws-elasticloadbalancing');
2+
import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2');
3+
4+
/**
5+
* The generations of AWS load balancing solutions.
6+
*/
7+
export enum LoadBalancerGeneration {
8+
/**
9+
* The first generation (ELB Classic).
10+
*/
11+
FIRST = 0,
12+
13+
/**
14+
* The second generation (ALB and NLB).
15+
*/
16+
SECOND = 1
17+
}
18+
19+
/**
20+
* An interface of an abstract load balancer, as needed by CodeDeploy.
21+
* Create instances using the static factory methods:
22+
* {@link #classic}, {@link #application} and {@link #network}.
23+
*/
24+
export abstract class LoadBalancer {
25+
/**
26+
* Creates a new CodeDeploy load balancer from a Classic ELB Load Balancer.
27+
*
28+
* @param loadBalancer a classic ELB Load Balancer
29+
*/
30+
public static classic(loadBalancer: elb.LoadBalancer): LoadBalancer {
31+
class ClassicLoadBalancer extends LoadBalancer {
32+
public readonly generation = LoadBalancerGeneration.FIRST;
33+
public readonly name = loadBalancer.loadBalancerName;
34+
}
35+
36+
return new ClassicLoadBalancer();
37+
}
38+
39+
/**
40+
* Creates a new CodeDeploy load balancer from an Application Load Balancer Target Group.
41+
*
42+
* @param albTargetGroup an ALB Target Group
43+
*/
44+
public static application(albTargetGroup: elbv2.ApplicationTargetGroup): LoadBalancer {
45+
class AlbLoadBalancer extends LoadBalancer {
46+
public readonly generation = LoadBalancerGeneration.SECOND;
47+
public readonly name = albTargetGroup.targetGroupName;
48+
}
49+
50+
return new AlbLoadBalancer();
51+
}
52+
53+
/**
54+
* Creates a new CodeDeploy load balancer from a Network Load Balancer Target Group.
55+
*
56+
* @param nlbTargetGroup an NLB Target Group
57+
*/
58+
public static network(nlbTargetGroup: elbv2.NetworkTargetGroup): LoadBalancer {
59+
class NlbLoadBalancer extends LoadBalancer {
60+
public readonly generation = LoadBalancerGeneration.SECOND;
61+
public readonly name = nlbTargetGroup.targetGroupName;
62+
}
63+
64+
return new NlbLoadBalancer();
65+
}
66+
67+
public abstract readonly generation: LoadBalancerGeneration;
68+
public abstract readonly name: string;
69+
}

‎packages/@aws-cdk/aws-codedeploy/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@
6363
"devDependencies": {
6464
"@aws-cdk/assert": "^0.31.0",
6565
"@aws-cdk/aws-ec2": "^0.31.0",
66-
"@aws-cdk/aws-elasticloadbalancing": "^0.31.0",
67-
"@aws-cdk/aws-elasticloadbalancingv2": "^0.31.0",
6866
"cdk-build-tools": "^0.31.0",
6967
"cdk-integ-tools": "^0.31.0",
7068
"cfn2ts": "^0.31.0",
@@ -73,7 +71,8 @@
7371
"dependencies": {
7472
"@aws-cdk/aws-autoscaling": "^0.31.0",
7573
"@aws-cdk/aws-cloudwatch": "^0.31.0",
76-
"@aws-cdk/aws-codedeploy-api": "^0.31.0",
74+
"@aws-cdk/aws-elasticloadbalancing": "^0.31.0",
75+
"@aws-cdk/aws-elasticloadbalancingv2": "^0.31.0",
7776
"@aws-cdk/aws-iam": "^0.31.0",
7877
"@aws-cdk/aws-lambda": "^0.31.0",
7978
"@aws-cdk/aws-s3": "^0.31.0",
@@ -83,7 +82,8 @@
8382
"peerDependencies": {
8483
"@aws-cdk/aws-autoscaling": "^0.31.0",
8584
"@aws-cdk/aws-cloudwatch": "^0.31.0",
86-
"@aws-cdk/aws-codedeploy-api": "^0.31.0",
85+
"@aws-cdk/aws-elasticloadbalancing": "^0.31.0",
86+
"@aws-cdk/aws-elasticloadbalancingv2": "^0.31.0",
8787
"@aws-cdk/aws-iam": "^0.31.0",
8888
"@aws-cdk/aws-lambda": "^0.31.0",
8989
"@aws-cdk/aws-s3": "^0.31.0",

‎packages/@aws-cdk/aws-codedeploy/test/server/integ.deployment-group.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ elb.addListener({
2525
new codedeploy.ServerDeploymentGroup(stack, 'CodeDeployGroup', {
2626
deploymentConfig: codedeploy.ServerDeploymentConfig.AllAtOnce,
2727
autoScalingGroups: [asg],
28-
loadBalancer: elb,
28+
loadBalancer: codedeploy.LoadBalancer.classic(elb),
2929
alarms: [
3030
new cloudwatch.Alarm(stack, 'Alarm1', {
3131
metric: new cloudwatch.Metric({

‎packages/@aws-cdk/aws-codedeploy/test/server/test.deployment-group.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export = {
101101
const targetGroup = listener.addTargets('Fleet', { protocol: lbv2.ApplicationProtocol.Http });
102102

103103
new codedeploy.ServerDeploymentGroup(stack, 'DeploymentGroup', {
104-
loadBalancer: targetGroup,
104+
loadBalancer: codedeploy.LoadBalancer.application(targetGroup),
105105
});
106106

107107
expect(stack).to(haveResource('AWS::CodeDeploy::DeploymentGroup', {
@@ -135,7 +135,7 @@ export = {
135135
const targetGroup = listener.addTargets('Fleet', { port: 80 });
136136

137137
new codedeploy.ServerDeploymentGroup(stack, 'DeploymentGroup', {
138-
loadBalancer: targetGroup,
138+
loadBalancer: codedeploy.LoadBalancer.network(targetGroup),
139139
});
140140

141141
expect(stack).to(haveResource('AWS::CodeDeploy::DeploymentGroup', {

‎packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import codedeploy = require('@aws-cdk/aws-codedeploy-api');
21
import {
32
AnyIPv4, Connections, IConnectable, IPortRange, ISecurityGroup,
43
IVpcNetwork, IVpcSubnet, SecurityGroup, TcpPort } from '@aws-cdk/aws-ec2';
@@ -188,7 +187,7 @@ export enum LoadBalancingProtocol {
188187
*
189188
* Routes to a fleet of of instances in a VPC.
190189
*/
191-
export class LoadBalancer extends Resource implements IConnectable, codedeploy.ILoadBalancer {
190+
export class LoadBalancer extends Resource implements IConnectable {
192191
/**
193192
* Control all connections from and to this load balancer
194193
*/
@@ -314,13 +313,6 @@ export class LoadBalancer extends Resource implements IConnectable, codedeploy.I
314313
return this.elb.loadBalancerSourceSecurityGroupOwnerAlias;
315314
}
316315

317-
public asCodeDeployLoadBalancer(): codedeploy.ILoadBalancerProps {
318-
return {
319-
generation: codedeploy.LoadBalancerGeneration.First,
320-
name: this.loadBalancerName,
321-
};
322-
}
323-
324316
/**
325317
* Allow connections to all existing targets on new instance port
326318
*/

‎packages/@aws-cdk/aws-elasticloadbalancing/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,11 @@
6565
"pkglint": "^0.31.0"
6666
},
6767
"dependencies": {
68-
"@aws-cdk/aws-codedeploy-api": "^0.31.0",
6968
"@aws-cdk/aws-ec2": "^0.31.0",
7069
"@aws-cdk/cdk": "^0.31.0"
7170
},
7271
"homepage": "https://github.com/awslabs/aws-cdk",
7372
"peerDependencies": {
74-
"@aws-cdk/aws-codedeploy-api": "^0.31.0",
7573
"@aws-cdk/aws-ec2": "^0.31.0",
7674
"@aws-cdk/cdk": "^0.31.0"
7775
},

‎packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import codedeploy = require('@aws-cdk/aws-codedeploy-api');
21
import ec2 = require('@aws-cdk/aws-ec2');
32
import cdk = require('@aws-cdk/cdk');
43
import { CfnTargetGroup } from '../elasticloadbalancingv2.generated';
@@ -131,7 +130,7 @@ export interface HealthCheck {
131130
/**
132131
* Define the target of a load balancer
133132
*/
134-
export abstract class TargetGroupBase extends cdk.Construct implements ITargetGroup, codedeploy.ILoadBalancer {
133+
export abstract class TargetGroupBase extends cdk.Construct implements ITargetGroup {
135134
/**
136135
* The ARN of the target group
137136
*/
@@ -275,13 +274,6 @@ export abstract class TargetGroupBase extends cdk.Construct implements ITargetGr
275274
};
276275
}
277276

278-
public asCodeDeployLoadBalancer(): codedeploy.ILoadBalancerProps {
279-
return {
280-
generation: codedeploy.LoadBalancerGeneration.Second,
281-
name: this.targetGroupName,
282-
};
283-
}
284-
285277
/**
286278
* Register the given load balancing target as part of this group
287279
*/

‎packages/@aws-cdk/aws-elasticloadbalancingv2/package-lock.json

+1-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk/aws-elasticloadbalancingv2/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
"dependencies": {
6868
"@aws-cdk/aws-certificatemanager": "^0.31.0",
6969
"@aws-cdk/aws-cloudwatch": "^0.31.0",
70-
"@aws-cdk/aws-codedeploy-api": "^0.31.0",
7170
"@aws-cdk/aws-ec2": "^0.31.0",
7271
"@aws-cdk/aws-iam": "^0.31.0",
7372
"@aws-cdk/aws-route53": "^0.31.0",
@@ -78,7 +77,6 @@
7877
"peerDependencies": {
7978
"@aws-cdk/aws-certificatemanager": "^0.31.0",
8079
"@aws-cdk/aws-cloudwatch": "^0.31.0",
81-
"@aws-cdk/aws-codedeploy-api": "^0.31.0",
8280
"@aws-cdk/aws-ec2": "^0.31.0",
8381
"@aws-cdk/aws-iam": "^0.31.0",
8482
"@aws-cdk/aws-route53": "^0.31.0",

0 commit comments

Comments
 (0)