# LoadBalancerProps

Construction properties for a LoadBalancer.

Used as props by: [LoadBalancer](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancing.LoadBalancer.html)

- Source: [`aws-elasticloadbalancing/lib/load-balancer.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-elasticloadbalancing/lib/load-balancer.ts#L28)

## Example

TypeScript:

```ts
declare const cluster: ecs.Cluster;
declare const taskDefinition: ecs.TaskDefinition;
declare const vpc: ec2.Vpc;
const service = new ecs.Ec2Service(this, 'Service', { cluster, taskDefinition, minHealthyPercent: 100 });

const lb = new elb.LoadBalancer(this, 'LB', { vpc });
lb.addListener({ externalPort: 80 });
lb.addTarget(service);
```

Python:

```python
# cluster: ecs.Cluster
# task_definition: ecs.TaskDefinition
# vpc: ec2.Vpc

service = ecs.Ec2Service(self, "Service", cluster=cluster, task_definition=task_definition, min_healthy_percent=100)

lb = elb.LoadBalancer(self, "LB", vpc=vpc)
lb.add_listener(external_port=80)
lb.add_target(service)
```

Java:

```java
Cluster cluster;
TaskDefinition taskDefinition;
Vpc vpc;

Ec2Service service = Ec2Service.Builder.create(this, "Service").cluster(cluster).taskDefinition(taskDefinition).minHealthyPercent(100).build();

LoadBalancer lb = LoadBalancer.Builder.create(this, "LB").vpc(vpc).build();
lb.addListener(LoadBalancerListener.builder().externalPort(80).build());
lb.addTarget(service);
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Cluster cluster;
TaskDefinition taskDefinition;
Vpc vpc;

var service = new Ec2Service(this, "Service", new Ec2ServiceProps { Cluster = cluster, TaskDefinition = taskDefinition, MinHealthyPercent = 100 });

var lb = new LoadBalancer(this, "LB", new LoadBalancerProps { Vpc = vpc });
lb.AddListener(new LoadBalancerListener { ExternalPort = 80 });
lb.AddTarget(service);
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var cluster Cluster
var taskDefinition TaskDefinition
var vpc Vpc

service := ecs.NewEc2Service(this, jsii.String("Service"), &Ec2ServiceProps{
	Cluster: Cluster,
	TaskDefinition: TaskDefinition,
	MinHealthyPercent: jsii.Number(100),
})

lb := elb.NewLoadBalancer(this, jsii.String("LB"), &LoadBalancerProps{
	Vpc: Vpc,
})
lb.AddListener(&LoadBalancerListener{
	ExternalPort: jsii.Number(80),
})
lb.AddTarget(service)
```

## Properties

- `accessLoggingPolicy`: [CfnLoadBalancer.AccessLoggingPolicyProperty](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancing.CfnLoadBalancer.AccessLoggingPolicyProperty.html) = disabled — Enable Loadbalancer access logs Can be used to avoid manual work as aws console Required S3 bucket name , enabled flag Can add interval for pushing log Can set bucket prefix in order to provide folder name inside bucket.

- `crossZone`: boolean = true — Whether cross zone load balancing is enabled.

  This controls whether the load balancer evenly distributes requests
  across each availability zone

- `healthCheck`: [HealthCheck](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancing.HealthCheck.html) = None. — Health check settings for the load balancing targets.

  Not required but recommended.

- `internetFacing`: boolean = false — Whether this is an internet-facing Load Balancer.

  This controls whether the LB has a public IP address assigned. It does
  not open up the Load Balancer's security groups to public internet access.

- `listeners`: [LoadBalancerListener](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancing.LoadBalancerListener.html)[] — What listeners to set up for the load balancer.

  Can also be added by .addListener()

- `subnetSelection`: [SubnetSelection](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.SubnetSelection.html) — Which subnets to deploy the load balancer.

  **Default:** Public subnets if internetFacing, Private subnets otherwise

  Can be used to define a specific set of subnets to deploy the load balancer to.
  Useful multiple public or private subnets are covering the same availability zone.

- `targets`: [ILoadBalancerTarget](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancing.ILoadBalancerTarget.html)[] = None. — What targets to load balance to.

  Can also be added by .addTarget()

- `vpc`: [IVpc](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) (required) — VPC network of the fleet instances.
