LoadBalancer

class aws_cdk.aws_elasticloadbalancing.LoadBalancer(scope, id, *, vpc, cross_zone=None, health_check=None, internet_facing=None, listeners=None, subnet_selection=None, targets=None)

Bases: aws_cdk.core.Resource

A load balancer with a single listener.

Routes to a fleet of of instances in a VPC.

__init__(scope, id, *, vpc, cross_zone=None, health_check=None, internet_facing=None, listeners=None, subnet_selection=None, targets=None)
Parameters
  • scope (Construct) –

  • id (str) –

  • vpc (IVpc) – VPC network of the fleet instances.

  • cross_zone (Optional[bool]) – Whether cross zone load balancing is enabled. This controls whether the load balancer evenly distributes requests across each availability zone Default: true

  • health_check (Optional[HealthCheck]) – Health check settings for the load balancing targets. Not required but recommended. Default: - None.

  • internet_facing (Optional[bool]) – 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. Default: false

  • listeners (Optional[List[LoadBalancerListener]]) – What listeners to set up for the load balancer. Can also be added by .addListener() Default: -

  • subnet_selection (Optional[SubnetSelection]) – 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. Default: - Public subnets if internetFacing, Private subnets otherwise

  • targets (Optional[List[ILoadBalancerTarget]]) – What targets to load balance to. Can also be added by .addTarget() Default: - None.

Return type

None

Methods

add_listener(*, external_port, allow_connections_from=None, external_protocol=None, internal_port=None, internal_protocol=None, policy_names=None, ssl_certificate_id=None)

Add a backend to the load balancer.

Parameters
  • external_port (Union[int, float]) – External listening port.

  • allow_connections_from (Optional[List[IConnectable]]) – 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). Default: Anywhere

  • external_protocol (Optional[LoadBalancingProtocol]) – 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.

  • internal_port (Union[int, float, None]) – Instance listening port. Same as the externalPort if not specified. Default: externalPort

  • internal_protocol (Optional[LoadBalancingProtocol]) – 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’.

  • policy_names (Optional[List[str]]) – SSL policy names.

  • ssl_certificate_id (Optional[str]) – ID of SSL certificate.

return :rtype: ListenerPort :return: A ListenerPort object that controls connections to the listener port

add_target(target)
Parameters

target (ILoadBalancerTarget) –

Return type

None

to_string()

Returns a string representation of this construct.

Return type

str

Attributes

connections

Control all connections from and to this load balancer.

Return type

Connections

listener_ports

An object controlling specifically the connections for each listener added to this load balancer.

Return type

List[ListenerPort]

load_balancer_canonical_hosted_zone_name

attribute: :attribute:: true

Return type

str

load_balancer_canonical_hosted_zone_name_id

attribute: :attribute:: true

Return type

str

load_balancer_dns_name

attribute: :attribute:: true

Return type

str

load_balancer_name

attribute: :attribute:: true

Return type

str

load_balancer_source_security_group_group_name

attribute: :attribute:: true

Return type

str

load_balancer_source_security_group_owner_alias

attribute: :attribute:: true

Return type

str

node

The construct tree node associated with this construct.

Return type

ConstructNode

stack

The stack in which this resource is defined.

Return type

Stack

Static Methods

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters

x (Any) –

Return type

bool