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(elasticloadbalancingv2): minimum Loadbalancer Capacity Unit (LCU) reservation #32382

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 31 additions & 0 deletions packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,20 @@ const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', {
});
```

### Defining a reserved Application Load Balancer Capacity Unit (LCU)

You can define a [reserved LCU for your Application Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/capacity-unit-reservation.html).
To reserve an LCU, you must specify a `minimumCapacityUnit`.

```ts
declare const vpc: ec2.Vpc;

const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', {
vpc,
minimumCapacityUnit: 10,
});
```

## Defining a Network Load Balancer

Network Load Balancers are defined in a similar way to Application Load
Expand Down Expand Up @@ -442,6 +456,23 @@ lb.addSecurityGroup(sg2);
lb.connections.allowFromAnyIpv4(ec2.Port.tcp(80));
```

### Defining a reserved Network Load Balancer Capacity Unit (LCU)

You can define a [reserved LCU for your Network Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/capacity-unit-reservation.html).

When requesting a LCU reservation, convert your capacity needs from Mbps to LCUs using the conversion rate of 1 LCU to 2.2 Mbps.

To reserve an LCU, you must specify a `minimumCapacityUnit`.

```ts
declare const vpc: ec2.Vpc;

const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', {
vpc,
minimumCapacityUnit: 10,
});
```

## Targets and Target Groups

Application and Network Load Balancers organize load balancing targets in Target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ export interface BaseLoadBalancerProps {
* @default - false for internet-facing load balancers and true for internal load balancers
*/
readonly denyAllIgwTraffic?: boolean;

/**
* The minimum capacity (LCU) for a load balancer.
*
* @default undefined - ELB default is 0 LCU
*
* @see https://docs.aws.amazon.com/elasticloadbalancing/latest/application/capacity-unit-reservation.html
* @see https://docs.aws.amazon.com/elasticloadbalancing/latest/network/capacity-unit-reservation.html
* @see https://exampleloadbalancer.com/ondemand_capacity_reservation_calculator.html
*/
readonly minimumCapacityUnit?: number;
}

export interface ILoadBalancerV2 extends IResource {
Expand Down Expand Up @@ -239,11 +250,19 @@ export abstract class BaseLoadBalancer extends Resource {
throw new Error(`'ipAddressType' DUAL_STACK_WITHOUT_PUBLIC_IPV4 can only be used with Application Load Balancer, got ${additionalProps.type}`);
}

const minimumCapacityUnit = baseProps.minimumCapacityUnit;
if (minimumCapacityUnit && !Token.isUnresolved(minimumCapacityUnit) && (minimumCapacityUnit < 0 || Number.isInteger(minimumCapacityUnit))) {
throw new Error(`'minimumCapacityUnit' must be a non-negative integer, got ${minimumCapacityUnit}`);
}

const resource = new CfnLoadBalancer(this, 'Resource', {
name: this.physicalName,
subnets: subnetIds,
scheme: internetFacing ? 'internet-facing' : 'internal',
loadBalancerAttributes: Lazy.any({ produce: () => renderAttributes(this.attributes) }, { omitEmptyArray: true } ),
minimumLoadBalancerCapacity: minimumCapacityUnit ? {
capacityUnits: minimumCapacityUnit,
} : undefined,
...additionalProps,
});
if (internetFacing) {
Expand Down
Loading