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-elasticloadbalancing): add crossZone property #2787

Merged
merged 6 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@
"Protocol": "http"
}
],
"CrossZone": true,
"HealthCheck": {
"HealthyThreshold": "2",
"Interval": "30",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@
"Protocol": "http"
}
],
"CrossZone": true,
"Scheme": "internal",
"SecurityGroups": [
{
Expand Down
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 true
*/
readonly crossZone?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does true make more sense as a default value here? I would feel better with that as a default value, and it seems the ELB team agrees:

According to: https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/enable-disable-crosszone-lb.html

With the AWS Management Console, the option to enable cross-zone load balancing is selected by default.

Given that we kind of see the CDK as the "AWS console but without clicking", it makes sense to me that the recommended defaults would be the same between console and CDK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rix0rrr good suggestion! I was just merely following the CloudFormation documentation.

I've updated my PR based on your recommendation. Let me know what you think.

}

/**
Expand Down Expand Up @@ -226,6 +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 === undefined || props.crossZone) ? true : 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 @@ -228,6 +228,7 @@
"Protocol": "http"
}
],
"CrossZone": true,
"HealthCheck": {
"HealthyThreshold": "2",
"Interval": "30",
Expand Down Expand Up @@ -255,4 +256,4 @@
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,64 @@ 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();
},

'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 {
Expand Down