# LoadBalancerListener

Add a backend to the load balancer.

Used as argument in: [LoadBalancer.addListener](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancing.LoadBalancer.html#addlistener)

- 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#L174)

## Example

TypeScript:

```ts
declare const vpc: ec2.IVpc;
const lb = new elb.LoadBalancer(this, 'LB', {
  vpc,
  internetFacing: true,
  healthCheck: {
    port: 80,
  },
});

declare const myAutoScalingGroup: autoscaling.AutoScalingGroup;
lb.addTarget(myAutoScalingGroup);
lb.addListener({
  externalPort: 80,
});
```

Python:

```python
# vpc: ec2.IVpc

# my_auto_scaling_group: autoscaling.AutoScalingGroup

lb = elb.LoadBalancer(self, "LB",
    vpc=vpc,
    internet_facing=True,
    health_check=elb.HealthCheck(
        port=80
    )
)
lb.add_target(my_auto_scaling_group)
lb.add_listener(
    external_port=80
)
```

Java:

```java
IVpc vpc;

AutoScalingGroup myAutoScalingGroup;

LoadBalancer lb = LoadBalancer.Builder.create(this, "LB")
        .vpc(vpc)
        .internetFacing(true)
        .healthCheck(HealthCheck.builder()
                .port(80)
                .build())
        .build();
lb.addTarget(myAutoScalingGroup);
lb.addListener(LoadBalancerListener.builder()
        .externalPort(80)
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
IVpc vpc;

AutoScalingGroup myAutoScalingGroup;

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

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc IVpc

var myAutoScalingGroup AutoScalingGroup

lb := elb.NewLoadBalancer(this, jsii.String("LB"), &LoadBalancerProps{
	Vpc: Vpc,
	InternetFacing: jsii.Boolean(true),
	HealthCheck: &HealthCheck{
		Port: jsii.Number(80),
	},
})
lb.AddTarget(myAutoScalingGroup)
lb.AddListener(&LoadBalancerListener{
	ExternalPort: jsii.Number(80),
})
```

## Properties

- `allowConnectionsFrom`: [IConnectable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IConnectable.html)[] = Anywhere — Allow connections to the load balancer from the given set of connection peers.

  By default, connections will be allowed from anywhere. Set this to an empty list
  to deny connections, or supply a custom list of peers to allow connections from
  (IP ranges or security groups).

- `externalPort`: number (required) — External listening port.

- `externalProtocol`: [LoadBalancingProtocol](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancing.LoadBalancingProtocol.html) — What public protocol to use for load balancing.

  Either 'tcp', 'ssl', 'http' or 'https'.

  May be omitted if the external port is either 80 or 443.

- `internalPort`: number = externalPort — Instance listening port.

  Same as the externalPort if not specified.

- `internalProtocol`: [LoadBalancingProtocol](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancing.LoadBalancingProtocol.html) — What public protocol to use for load balancing.

  Either 'tcp', 'ssl', 'http' or 'https'.

  May be omitted if the internal port is either 80 or 443.

  The instance protocol is 'tcp' if the front-end protocol
  is 'tcp' or 'ssl', the instance protocol is 'http' if the
  front-end protocol is 'https'.

- `policyNames`: string[] — SSL policy names.

- `sslCertificateArn`: string = none — the ARN of the SSL certificate.
