# LoadBalancerV2Origin

An Origin for a v2 load balancer.

Extends: [OriginBase](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.OriginBase.html) › [HttpOrigin](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront_origins.HttpOrigin.html) › LoadBalancerV2Origin
Implements: [IOrigin](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.IOrigin.html)

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

## Example

TypeScript:

```ts
// Creates a distribution from an ELBv2 load balancer
declare const vpc: ec2.Vpc;
// Create an application load balancer in a VPC. 'internetFacing' must be 'true'
// for CloudFront to access the load balancer and use it as an origin.
const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', {
  vpc,
  internetFacing: true,
});
new cloudfront.Distribution(this, 'myDist', {
  defaultBehavior: { origin: new origins.LoadBalancerV2Origin(lb) },
});
```

Python:

```python
# Creates a distribution from an ELBv2 load balancer
# vpc: ec2.Vpc

# Create an application load balancer in a VPC. 'internetFacing' must be 'true'
# for CloudFront to access the load balancer and use it as an origin.
lb = elbv2.ApplicationLoadBalancer(self, "LB",
    vpc=vpc,
    internet_facing=True
)
cloudfront.Distribution(self, "myDist",
    default_behavior=cloudfront.BehaviorOptions(origin=origins.LoadBalancerV2Origin(lb))
)
```

Java:

```java
// Creates a distribution from an ELBv2 load balancer
Vpc vpc;

// Create an application load balancer in a VPC. 'internetFacing' must be 'true'
// for CloudFront to access the load balancer and use it as an origin.
ApplicationLoadBalancer lb = ApplicationLoadBalancer.Builder.create(this, "LB")
        .vpc(vpc)
        .internetFacing(true)
        .build();
Distribution.Builder.create(this, "myDist")
        .defaultBehavior(BehaviorOptions.builder().origin(new LoadBalancerV2Origin(lb)).build())
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// Creates a distribution from an ELBv2 load balancer
Vpc vpc;

// Create an application load balancer in a VPC. 'internetFacing' must be 'true'
// for CloudFront to access the load balancer and use it as an origin.
var lb = new ApplicationLoadBalancer(this, "LB", new ApplicationLoadBalancerProps {
    Vpc = vpc,
    InternetFacing = true
});
new Distribution(this, "myDist", new DistributionProps {
    DefaultBehavior = new BehaviorOptions { Origin = new LoadBalancerV2Origin(lb) }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Creates a distribution from an ELBv2 load balancer
var vpc Vpc

// Create an application load balancer in a VPC. 'internetFacing' must be 'true'
// for CloudFront to access the load balancer and use it as an origin.
lb := elbv2.NewApplicationLoadBalancer(this, jsii.String("LB"), &ApplicationLoadBalancerProps{
	Vpc: Vpc,
	InternetFacing: jsii.Boolean(true),
})
cloudfront.NewDistribution(this, jsii.String("myDist"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewLoadBalancerV2Origin(lb),
	},
})
```

## Initializer

TypeScript:

```ts
new LoadBalancerV2Origin(loadBalancer: ILoadBalancerV2, props?: LoadBalancerV2OriginProps)
```

Python:

```python
LoadBalancerV2Origin(load_balancer: ILoadBalancerV2, props: typing.Optional[LoadBalancerV2OriginProps] = None)
```

Java:

```java
new LoadBalancerV2Origin(ILoadBalancerV2 loadBalancer, LoadBalancerV2OriginProps props)
```

C# / .NET:

```csharp
new LoadBalancerV2Origin(ILoadBalancerV2 loadBalancer, LoadBalancerV2OriginProps? props = null)
```

Golang:

```go
NewLoadBalancerV2Origin(LoadBalancer ILoadBalancerV2, Props LoadBalancerV2OriginProps)
```

## Methods

- `bind(scope: Construct, options: OriginBindOptions): OriginBindConfig` — Binds the origin to the associated Distribution.

  Can be used to grant permissions, create dependent resources, etc.
