Skip to content
v2.278.0

LoadBalancerV2Origin Class ​

An Origin for a v2 load balancer.

Example ​

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
# 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
// 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();
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) }
});
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 ​

ts
new LoadBalancerV2Origin(loadBalancer: ILoadBalancerV2, props?: LoadBalancerV2OriginProps)
python
LoadBalancerV2Origin(load_balancer: ILoadBalancerV2, props: typing.Optional[LoadBalancerV2OriginProps] = None)
java
new LoadBalancerV2Origin(ILoadBalancerV2 loadBalancer, LoadBalancerV2OriginProps props)
csharp
new LoadBalancerV2Origin(ILoadBalancerV2 loadBalancer, LoadBalancerV2OriginProps? props = null)
go
NewLoadBalancerV2Origin(LoadBalancer ILoadBalancerV2, Props LoadBalancerV2OriginProps)

Methods ​

bind(scope: Construct, options: OriginBindOptions): OriginBindConfigdef bind(self, scope: Construct, options: OriginBindOptions) -> OriginBindConfigpublic OriginBindConfig bind(Construct scope, OriginBindOptions options)public OriginBindConfig Bind(Construct scope, OriginBindOptions options)func Bind(Scope Construct, Options OriginBindOptions) OriginBindConfig #
Binds the origin to the associated Distribution.

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