Skip to content

Commit

Permalink
feat(aws-elasticloadbalancing): add crossZone property
Browse files Browse the repository at this point in the history
Ability to enable cross-zone load balancing for a Classic Load Balancer

closes aws#2786
  • Loading branch information
ScOut3R committed Jun 7, 2019
1 parent e3df21a commit 0e5ec0c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};
Expand Down

0 comments on commit 0e5ec0c

Please sign in to comment.