class LoadBalancer (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.ElasticLoadBalancing.LoadBalancer |
Java | software.amazon.awscdk.services.elasticloadbalancing.LoadBalancer |
Python | aws_cdk.aws_elasticloadbalancing.LoadBalancer |
TypeScript (source) | @aws-cdk/aws-elasticloadbalancing » LoadBalancer |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
, IConnectable
A load balancer with a single listener.
Routes to a fleet of of instances in a VPC.
Example
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,
});
Initializer
new LoadBalancer(scope: Construct, id: string, props: LoadBalancerProps)
Parameters
- scope
Construct
- id
string
- props
Load
Balancer Props
Construct Props
Name | Type | Description |
---|---|---|
vpc | IVpc | VPC network of the fleet instances. |
access | Access | 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. |
cross | boolean | Whether cross zone load balancing is enabled. |
health | Health | Health check settings for the load balancing targets. |
internet | boolean | Whether this is an internet-facing Load Balancer. |
listeners? | Load [] | What listeners to set up for the load balancer. |
subnet | Subnet | Which subnets to deploy the load balancer. |
targets? | ILoad [] | What targets to load balance to. |
vpc
Type:
IVpc
VPC network of the fleet instances.
accessLoggingPolicy?
Type:
Access
(optional, default: 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?
Type:
boolean
(optional, default: true)
Whether cross zone load balancing is enabled.
This controls whether the load balancer evenly distributes requests across each availability zone
healthCheck?
Type:
Health
(optional, default: None.)
Health check settings for the load balancing targets.
Not required but recommended.
internetFacing?
Type:
boolean
(optional, default: 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?
Type:
Load
[]
(optional, default: -)
What listeners to set up for the load balancer.
Can also be added by .addListener()
subnetSelection?
Type:
Subnet
(optional, default: Public subnets if internetFacing, Private subnets otherwise)
Which subnets to deploy the load balancer.
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?
Type:
ILoad
[]
(optional, default: None.)
What targets to load balance to.
Can also be added by .addTarget()
Properties
Name | Type | Description |
---|---|---|
connections | Connections | Control all connections from and to this load balancer. |
env | Resource | The environment this resource belongs to. |
listener | Listener [] | An object controlling specifically the connections for each listener added to this load balancer. |
load | string | |
load | string | |
load | string | |
load | string | |
load | string | |
load | string | |
node | Construct | The construct tree node associated with this construct. |
stack | Stack | The stack in which this resource is defined. |
connections
Type:
Connections
Control all connections from and to this load balancer.
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
listenerPorts
Type:
Listener
[]
An object controlling specifically the connections for each listener added to this load balancer.
loadBalancerCanonicalHostedZoneName
Type:
string
loadBalancerCanonicalHostedZoneNameId
Type:
string
loadBalancerDnsName
Type:
string
loadBalancerName
Type:
string
loadBalancerSourceSecurityGroupGroupName
Type:
string
loadBalancerSourceSecurityGroupOwnerAlias
Type:
string
node
Type:
Construct
The construct tree node associated with this construct.
stack
Type:
Stack
The stack in which this resource is defined.
Methods
Name | Description |
---|---|
add | Add a backend to the load balancer. |
add | |
apply | Apply the given removal policy to this resource. |
to | Returns a string representation of this construct. |
Listener(listener)
addpublic addListener(listener: LoadBalancerListener): ListenerPort
Parameters
- listener
Load
Balancer Listener
Returns
Add a backend to the load balancer.
Target(target)
addpublic addTarget(target: ILoadBalancerTarget): void
Parameters
- target
ILoad
Balancer Target
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.