From 0e5ec0c77bbbbe49cef02ed95bc5fc542b8a79cf Mon Sep 17 00:00:00 2001 From: Mate GABRI Date: Fri, 7 Jun 2019 22:05:58 +1000 Subject: [PATCH 1/5] feat(aws-elasticloadbalancing): add crossZone property Ability to enable cross-zone load balancing for a Classic Load Balancer closes #2786 --- .../lib/load-balancer.ts | 11 +++++++++++ .../test/test.loadbalancer.ts | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts index 719d558942405..d41bc8be1c4ae 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts @@ -49,6 +49,16 @@ export interface LoadBalancerProps { * @default - None. */ readonly healthCheck?: HealthCheck; + + /** + * Whether cross zone load balancing is enabled + * + * This controls whether the load balancer evenly distributes requests + * across each availability zone + * + * @default - false. + */ + readonly crossZone?: boolean; } /** @@ -226,6 +236,7 @@ export class LoadBalancer extends Resource implements IConnectable { listeners: new Token(() => this.listeners), scheme: props.internetFacing ? 'internet-facing' : 'internal', healthCheck: props.healthCheck && healthCheckToJSON(props.healthCheck), + crossZone: props.crossZone || false, }); if (props.internetFacing) { this.elb.node.addDependency(...subnets.map(s => s.internetConnectivityEstablished)); diff --git a/packages/@aws-cdk/aws-elasticloadbalancing/test/test.loadbalancer.ts b/packages/@aws-cdk/aws-elasticloadbalancing/test/test.loadbalancer.ts index 96c94a973def7..2bc8bc954e83b 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancing/test/test.loadbalancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancing/test/test.loadbalancer.ts @@ -92,6 +92,25 @@ export = { ], })); + test.done(); + }, + + 'enable cross zone load balancing'(test: Test) { + // GIVEN + const stack = new Stack(); + const vpc = new Vpc(stack, 'VCP'); + + // WHEN + new LoadBalancer(stack, 'LB', { + vpc, + crossZone: true, + }); + + // THEN + expect(stack).to(haveResource('AWS::ElasticLoadBalancing::LoadBalancer', { + CrossZone: true + })); + test.done(); } }; From c51db5801bcd3bff224948c5d836345d9258d383 Mon Sep 17 00:00:00 2001 From: Mate GABRI Date: Fri, 7 Jun 2019 23:05:57 +1000 Subject: [PATCH 2/5] feat(aws-elasticloadbalancing): add crossZone property Update integration test synth fixes #2786 --- .../aws-elasticloadbalancing/test/integ.elb.expected.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-elasticloadbalancing/test/integ.elb.expected.json b/packages/@aws-cdk/aws-elasticloadbalancing/test/integ.elb.expected.json index e880c454c6447..4be71095b8cdd 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancing/test/integ.elb.expected.json +++ b/packages/@aws-cdk/aws-elasticloadbalancing/test/integ.elb.expected.json @@ -228,6 +228,7 @@ "Protocol": "http" } ], + "CrossZone": false, "HealthCheck": { "HealthyThreshold": "2", "Interval": "30", @@ -255,4 +256,4 @@ ] } } -} +} \ No newline at end of file From f9b81db789e39de6cebf0a1f5eafb8eae884cde3 Mon Sep 17 00:00:00 2001 From: Mate GABRI Date: Sat, 8 Jun 2019 00:21:57 +1000 Subject: [PATCH 3/5] feat(aws-elasticloadbalancing): add crossZone property Update integration test synth for aws-autoscaling fixes #2786 --- .../test/integ.asg-w-classic-loadbalancer.expected.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/@aws-cdk/aws-autoscaling/test/integ.asg-w-classic-loadbalancer.expected.json b/packages/@aws-cdk/aws-autoscaling/test/integ.asg-w-classic-loadbalancer.expected.json index 53dbaa02298cd..00724bf5405be 100644 --- a/packages/@aws-cdk/aws-autoscaling/test/integ.asg-w-classic-loadbalancer.expected.json +++ b/packages/@aws-cdk/aws-autoscaling/test/integ.asg-w-classic-loadbalancer.expected.json @@ -691,6 +691,7 @@ "Protocol": "http" } ], + "CrossZone": false, "HealthCheck": { "HealthyThreshold": "2", "Interval": "30", From 9b63149ae7aad1989da2fc05b39b85c98973d545 Mon Sep 17 00:00:00 2001 From: Mate GABRI Date: Sat, 8 Jun 2019 02:44:37 +1000 Subject: [PATCH 4/5] feat(aws-elasticloadbalancing): add crossZone property Update integration test synth for aws-codedeploy fixes #2786 --- .../test/server/integ.deployment-group.expected.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/@aws-cdk/aws-codedeploy/test/server/integ.deployment-group.expected.json b/packages/@aws-cdk/aws-codedeploy/test/server/integ.deployment-group.expected.json index f6e9aef12d51e..ef43fb1170a22 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/server/integ.deployment-group.expected.json +++ b/packages/@aws-cdk/aws-codedeploy/test/server/integ.deployment-group.expected.json @@ -725,6 +725,7 @@ "Protocol": "http" } ], + "CrossZone": false, "Scheme": "internal", "SecurityGroups": [ { From 3a843843633a7942365a510e61b9867d85e563f3 Mon Sep 17 00:00:00 2001 From: Mate GABRI Date: Wed, 12 Jun 2019 12:34:38 +1000 Subject: [PATCH 5/5] feat(aws-elasticloadbalancing): add crossZone property (#2786) enable cross-zone load balancing by default to comply with AWS Console behaviour --- ...g.asg-w-classic-loadbalancer.expected.json | 2 +- .../integ.deployment-group.expected.json | 2 +- .../lib/load-balancer.ts | 4 +- .../test/integ.elb.expected.json | 2 +- .../test/test.loadbalancer.ts | 40 ++++++++++++++++++- 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/packages/@aws-cdk/aws-autoscaling/test/integ.asg-w-classic-loadbalancer.expected.json b/packages/@aws-cdk/aws-autoscaling/test/integ.asg-w-classic-loadbalancer.expected.json index 00724bf5405be..c5482ded0fe5b 100644 --- a/packages/@aws-cdk/aws-autoscaling/test/integ.asg-w-classic-loadbalancer.expected.json +++ b/packages/@aws-cdk/aws-autoscaling/test/integ.asg-w-classic-loadbalancer.expected.json @@ -691,7 +691,7 @@ "Protocol": "http" } ], - "CrossZone": false, + "CrossZone": true, "HealthCheck": { "HealthyThreshold": "2", "Interval": "30", diff --git a/packages/@aws-cdk/aws-codedeploy/test/server/integ.deployment-group.expected.json b/packages/@aws-cdk/aws-codedeploy/test/server/integ.deployment-group.expected.json index ef43fb1170a22..74cf1cf212580 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/server/integ.deployment-group.expected.json +++ b/packages/@aws-cdk/aws-codedeploy/test/server/integ.deployment-group.expected.json @@ -725,7 +725,7 @@ "Protocol": "http" } ], - "CrossZone": false, + "CrossZone": true, "Scheme": "internal", "SecurityGroups": [ { diff --git a/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts index 95cb613d7103a..5eda1e6af5eb7 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts @@ -56,7 +56,7 @@ export interface LoadBalancerProps { * This controls whether the load balancer evenly distributes requests * across each availability zone * - * @default - false. + * @default true */ readonly crossZone?: boolean; } @@ -236,7 +236,7 @@ export class LoadBalancer extends Resource implements IConnectable { listeners: Lazy.anyValue({ produce: () => this.listeners }), scheme: props.internetFacing ? 'internet-facing' : 'internal', healthCheck: props.healthCheck && healthCheckToJSON(props.healthCheck), - crossZone: props.crossZone || false, + crossZone: (props.crossZone === undefined || props.crossZone) ? true : false }); if (props.internetFacing) { this.elb.node.addDependency(...subnets.map(s => s.internetConnectivityEstablished)); diff --git a/packages/@aws-cdk/aws-elasticloadbalancing/test/integ.elb.expected.json b/packages/@aws-cdk/aws-elasticloadbalancing/test/integ.elb.expected.json index 4be71095b8cdd..e56301280aec1 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancing/test/integ.elb.expected.json +++ b/packages/@aws-cdk/aws-elasticloadbalancing/test/integ.elb.expected.json @@ -228,7 +228,7 @@ "Protocol": "http" } ], - "CrossZone": false, + "CrossZone": true, "HealthCheck": { "HealthyThreshold": "2", "Interval": "30", diff --git a/packages/@aws-cdk/aws-elasticloadbalancing/test/test.loadbalancer.ts b/packages/@aws-cdk/aws-elasticloadbalancing/test/test.loadbalancer.ts index 2bc8bc954e83b..e228d4bce9f35 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancing/test/test.loadbalancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancing/test/test.loadbalancer.ts @@ -112,7 +112,45 @@ export = { })); test.done(); - } + }, + + 'disable cross zone load balancing'(test: Test) { + // GIVEN + const stack = new Stack(); + const vpc = new Vpc(stack, 'VCP'); + + // WHEN + new LoadBalancer(stack, 'LB', { + vpc, + crossZone: false, + }); + + // THEN + expect(stack).to(haveResource('AWS::ElasticLoadBalancing::LoadBalancer', { + CrossZone: false + })); + + test.done(); + }, + + 'cross zone load balancing enabled by default'(test: Test) { + // GIVEN + const stack = new Stack(); + const vpc = new Vpc(stack, 'VCP'); + + // WHEN + new LoadBalancer(stack, 'LB', { + vpc, + }); + + // THEN + expect(stack).to(haveResource('AWS::ElasticLoadBalancing::LoadBalancer', { + CrossZone: true + })); + + test.done(); + }, + }; class FakeTarget implements ILoadBalancerTarget {