# This file is automatically generated by botocraft. Do not edit directly.
# mypy: disable-error-code="index, override, assignment, union-attr, misc"
from botocraft.services.ec2 import Subnet, SubnetManager
from botocraft.services.ec2 import Instance, InstanceManager
from .abstract import (
Boto3Model,
ReadonlyBoto3Model,
PrimaryBoto3Model,
ReadonlyPrimaryBoto3Model,
Boto3ModelManager,
ReadonlyBoto3ModelManager,
)
from .abstract import PrimaryBoto3ModelQuerySet
from datetime import datetime
import builtins
from botocraft.mixins.elb import add_tags_for_list
from botocraft.services.ec2 import SecurityGroup, SecurityGroupManager
from botocraft.mixins.elb import add_attributes_for_get
from botocraft.mixins.elb import ClassicELBManagerMixin
from functools import cached_property
from pydantic import Field
from botocraft.mixins.elb import add_attributes_for_list
from collections import OrderedDict
from typing import ClassVar, Literal, Any, cast
from botocraft.services.ec2 import Vpc, VpcManager
from botocraft.mixins.tags import TagsDictMixin
from botocraft.mixins.elb import ClassicELBModelMixin
from botocraft.services.common import Tag
from botocraft.mixins.elb import add_tags_for_get
# ===============
# Managers
# ===============
[docs]class ClassicELBManager(ClassicELBManagerMixin, Boto3ModelManager):
service_name: str = "elb"
[docs] def delete(self, LoadBalancerName: str) -> None:
"""
Deletes the specified load balancer.
Args:
LoadBalancerName: The name of the load balancer.
"""
args: dict[str, Any] = dict(LoadBalancerName=self.serialize(LoadBalancerName))
self.client.delete_load_balancer(
**{k: v for k, v in args.items() if v is not None}
)
[docs] @add_attributes_for_get
@add_tags_for_get
def get(self, LoadBalancerName: str) -> "ClassicELB | None":
"""
Describes the specified the load balancers. If no load balancers are specified,
the call describes all of your load balancers.
Args:
LoadBalancerName: The name of the classic load balancer.
"""
args: dict[str, Any] = dict(
LoadBalancerNames=self.serialize([LoadBalancerName])
)
_response = self.client.describe_load_balancers(
**{k: v for k, v in args.items() if v is not None}
)
response = DescribeAccessPointsOutput(**_response)
if response and response.LoadBalancerDescriptions:
self.sessionize(response.LoadBalancerDescriptions[0])
return response.LoadBalancerDescriptions[0]
return None
[docs] @add_attributes_for_list
@add_tags_for_list
def list(
self, *, LoadBalancerNames: "builtins.list[str] | None" = None
) -> PrimaryBoto3ModelQuerySet:
"""
Describes the specified the load balancers. If no load balancers are specified,
the call describes all of your load balancers.
Keyword Args:
LoadBalancerNames: The names of the load balancers.
"""
paginator = self.client.get_paginator("describe_load_balancers")
args: dict[str, Any] = dict(LoadBalancerNames=self.serialize(LoadBalancerNames))
response_iterator = paginator.paginate(
**{k: v for k, v in args.items() if v is not None}
)
results = []
for _response in response_iterator:
if list(_response.keys()) == ["ResponseMetadata"]:
break
if "ResponseMetadata" in _response:
del _response["ResponseMetadata"]
response = DescribeAccessPointsOutput(**_response)
if response.LoadBalancerDescriptions:
results.extend(response.LoadBalancerDescriptions)
else:
if getattr(response, "NextToken", None):
continue
break
self.sessionize(results)
if results and isinstance(results[0], Boto3Model):
return PrimaryBoto3ModelQuerySet(results)
return results
[docs] def enable_availability_zones(
self, LoadBalancerName: str, AvailabilityZones: "builtins.list[str]"
) -> "builtins.list[str]":
"""
Adds the specified Availability Zones to the set of Availability Zones for the
specified load balancer in EC2-Classic or a default VPC.
Args:
LoadBalancerName: The name of the load balancer.
AvailabilityZones: The Availability Zones. These must be in the same region as the load balancer.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
AvailabilityZones=self.serialize(AvailabilityZones),
)
_response = self.client.enable_availability_zones_for_load_balancer(
**{k: v for k, v in args.items() if v is not None}
)
response = AddAvailabilityZonesOutput(**_response)
results: "builtins.list[str]" = None
if response is not None:
results = response.AvailabilityZones
self.sessionize(results)
return cast("builtins.list[str]", results)
[docs] def disable_availability_zones(
self, LoadBalancerName: str, AvailabilityZones: "builtins.list[str]"
) -> "builtins.list[str]":
"""
Removes the specified Availability Zones from the set of Availability Zones for
the specified load balancer in EC2-Classic or a default VPC.
Args:
LoadBalancerName: The name of the load balancer.
AvailabilityZones: The Availability Zones.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
AvailabilityZones=self.serialize(AvailabilityZones),
)
_response = self.client.disable_availability_zones_for_load_balancer(
**{k: v for k, v in args.items() if v is not None}
)
response = RemoveAvailabilityZonesOutput(**_response)
results: "builtins.list[str]" = None
if response is not None:
results = response.AvailabilityZones
self.sessionize(results)
return cast("builtins.list[str]", results)
[docs] def register_instances(
self, LoadBalancerName: str, Instances: "builtins.list[ClassicELBInstance]"
) -> "builtins.list[ClassicELBInstance]":
"""
Adds the specified instances to the specified load balancer.
Args:
LoadBalancerName: The name of the load balancer.
Instances: The IDs of the instances.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
Instances=self.serialize(Instances),
)
_response = self.client.register_instances_with_load_balancer(
**{k: v for k, v in args.items() if v is not None}
)
response = RegisterEndPointsOutput(**_response)
results: "builtins.list[ClassicELBInstance]" = None
if response is not None:
results = response.Instances
self.sessionize(results)
return cast("builtins.list[ClassicELBInstance]", results)
[docs] def instance_health(
self,
LoadBalancerName: str,
*,
Instances: "builtins.list[ClassicELBInstance] | None" = None,
) -> "builtins.list[ClassicELBInstanceState]":
"""
Describes the state of the specified instances with respect to the specified
load balancer. If no instances are specified, the call describes the state of
all instances that are currently registered with the load balancer. If instances
are specified, their state is returned even if they are no longer registered
with the load balancer. The state of terminated instances is not returned.
Args:
LoadBalancerName: The name of the load balancer.
Keyword Args:
Instances: The IDs of the instances.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
Instances=self.serialize(Instances),
)
_response = self.client.describe_instance_health(
**{k: v for k, v in args.items() if v is not None}
)
response = DescribeEndPointStateOutput(**_response)
results: "builtins.list[ClassicELBInstanceState]" = None
if response is not None:
results = response.InstanceStates
self.sessionize(results)
return cast("builtins.list[ClassicELBInstanceState]", results)
[docs] def deregister_instances(
self, LoadBalancerName: str, Instances: "builtins.list[ClassicELBInstance]"
) -> "builtins.list[ClassicELBInstance]":
"""
Deregisters the specified instances from the specified load balancer. After the
instance is deregistered, it no longer receives traffic from the load balancer.
Args:
LoadBalancerName: The name of the load balancer.
Instances: The IDs of the instances.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
Instances=self.serialize(Instances),
)
_response = self.client.deregister_instances_from_load_balancer(
**{k: v for k, v in args.items() if v is not None}
)
response = DeregisterEndPointsOutput(**_response)
results: "builtins.list[ClassicELBInstance]" = None
if response is not None:
results = response.Instances
self.sessionize(results)
return cast("builtins.list[ClassicELBInstance]", results)
[docs] def add_listeners(
self, LoadBalancerName: str, Listeners: "builtins.list[ClassicELBListener]"
) -> None:
"""
Creates one or more listeners for the specified load balancer. If a listener
with the specified port does not already exist, it is created; otherwise, the
properties of the new listener must match the properties of the existing
listener.
Args:
LoadBalancerName: The name of the load balancer.
Listeners: The listeners.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
Listeners=self.serialize(Listeners),
)
self.client.create_load_balancer_listeners(
**{k: v for k, v in args.items() if v is not None}
)
[docs] def remove_listeners(
self, LoadBalancerName: str, LoadBalancerPorts: "builtins.list[int]"
) -> None:
"""
Deletes the specified listeners from the specified load balancer.
Args:
LoadBalancerName: The name of the load balancer.
LoadBalancerPorts: The client port numbers of the listeners.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
LoadBalancerPorts=self.serialize(LoadBalancerPorts),
)
self.client.delete_load_balancer_listeners(
**{k: v for k, v in args.items() if v is not None}
)
[docs] def describe_attributes(
self, LoadBalancerName: str
) -> "ClassicELBLoadBalancerAttributes":
"""
Describes the attributes for the specified load balancer.
Args:
LoadBalancerName: The name of the load balancer.
"""
args: dict[str, Any] = dict(LoadBalancerName=self.serialize(LoadBalancerName))
_response = self.client.describe_load_balancer_attributes(
**{k: v for k, v in args.items() if v is not None}
)
response = DescribeClassicELBAttributesResponse(**_response)
results: "ClassicELBLoadBalancerAttributes" = None
if response is not None:
results = response.LoadBalancerAttributes
self.sessionize(results)
return cast("ClassicELBLoadBalancerAttributes", results)
[docs] def modify_attributes(
self,
LoadBalancerName: str,
LoadBalancerAttributes: "ClassicELBLoadBalancerAttributes",
) -> "ClassicELBLoadBalancerAttributes":
"""
Modifies the attributes of the specified load balancer.
Args:
LoadBalancerName: The name of the load balancer.
LoadBalancerAttributes: The attributes for the load balancer.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
LoadBalancerAttributes=self.serialize(LoadBalancerAttributes),
)
_response = self.client.modify_load_balancer_attributes(
**{k: v for k, v in args.items() if v is not None}
)
response = ModifyLoadBalancerAttributesOutput(**_response)
results: "ClassicELBLoadBalancerAttributes" = None
if response is not None:
results = response.LoadBalancerAttributes
self.sessionize(results)
return cast("ClassicELBLoadBalancerAttributes", results)
[docs] def detach_from_subnets(
self, LoadBalancerName: str, Subnets: "builtins.list[str]"
) -> "builtins.list[str]":
"""
Removes the specified subnets from the set of configured subnets for the load
balancer.
Args:
LoadBalancerName: The name of the load balancer.
Subnets: The IDs of the subnets.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
Subnets=self.serialize(Subnets),
)
_response = self.client.detach_load_balancer_from_subnets(
**{k: v for k, v in args.items() if v is not None}
)
response = DetachLoadBalancerFromSubnetsOutput(**_response)
results: "builtins.list[str]" = None
if response is not None:
results = response.Subnets
self.sessionize(results)
return cast("builtins.list[str]", results)
[docs] def attach_to_subnets(
self, LoadBalancerName: str, Subnets: "builtins.list[str]"
) -> "builtins.list[str]":
"""
Adds one or more subnets to the set of configured subnets for the specified load
balancer.
Args:
LoadBalancerName: The name of the load balancer.
Subnets: The IDs of the subnets to add. You can add only one subnet per Availability Zone.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
Subnets=self.serialize(Subnets),
)
_response = self.client.attach_load_balancer_to_subnets(
**{k: v for k, v in args.items() if v is not None}
)
response = AttachLoadBalancerToSubnetsOutput(**_response)
results: "builtins.list[str]" = None
if response is not None:
results = response.Subnets
self.sessionize(results)
return cast("builtins.list[str]", results)
[docs] def apply_security_groups(
self, LoadBalancerName: str, SecurityGroups: "builtins.list[str]"
) -> "builtins.list[str]":
"""
Associates one or more security groups with your load balancer in a virtual
private cloud (VPC). The specified security groups override the previously
associated security groups.
Args:
LoadBalancerName: The name of the load balancer.
SecurityGroups: The IDs of the security groups to associate with the load balancer. Note that you cannot specify the
name of the security group.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
SecurityGroups=self.serialize(SecurityGroups),
)
_response = self.client.apply_security_groups_to_load_balancer(
**{k: v for k, v in args.items() if v is not None}
)
response = ApplySecurityGroupsToLoadBalancerOutput(**_response)
results: "builtins.list[str]" = None
if response is not None:
results = response.SecurityGroups
self.sessionize(results)
return cast("builtins.list[str]", results)
[docs] def set_ssl_certificate(
self, LoadBalancerName: str, LoadBalancerPort: int, SSLCertificateId: str
) -> None:
"""
Sets the certificate that terminates the specified listener's SSL connections.
The specified certificate replaces any prior certificate that was used on the
same load balancer and port.
Args:
LoadBalancerName: The name of the load balancer.
LoadBalancerPort: The port that uses the specified SSL certificate.
SSLCertificateId: The Amazon Resource Name (ARN) of the SSL certificate.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
LoadBalancerPort=self.serialize(LoadBalancerPort),
SSLCertificateId=self.serialize(SSLCertificateId),
)
self.client.set_load_balancer_listener_ssl_certificate(
**{k: v for k, v in args.items() if v is not None}
)
[docs] def set_listener_policies(
self,
LoadBalancerName: str,
LoadBalancerPort: int,
PolicyNames: "builtins.list[str]",
) -> None:
"""
Replaces the current set of policies for the specified load balancer port with
the specified set of policies.
Args:
LoadBalancerName: The name of the load balancer.
LoadBalancerPort: The external port of the load balancer.
PolicyNames: The names of the policies. This list must include all policies to be enabled. If you omit a policy that
is currently enabled, it is disabled. If the list is empty, all current policies are disabled.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
LoadBalancerPort=self.serialize(LoadBalancerPort),
PolicyNames=self.serialize(PolicyNames),
)
self.client.set_load_balancer_policies_of_listener(
**{k: v for k, v in args.items() if v is not None}
)
[docs] def set_backend_policies(
self,
LoadBalancerName: str,
InstancePort: int,
PolicyNames: "builtins.list[str]",
) -> None:
"""
Replaces the set of policies associated with the specified port on which the EC2
instance is listening with a new set of policies. At this time, only the back-
end server authentication policy type can be applied to the instance ports; this
policy type is composed of multiple public key policies.
Args:
LoadBalancerName: The name of the load balancer.
InstancePort: The port number associated with the EC2 instance.
PolicyNames: The names of the policies. If the list is empty, then all current polices are removed from the EC2
instance.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
InstancePort=self.serialize(InstancePort),
PolicyNames=self.serialize(PolicyNames),
)
self.client.set_load_balancer_policies_for_backend_server(
**{k: v for k, v in args.items() if v is not None}
)
[docs] def add_policy(
self,
LoadBalancerName: str,
PolicyName: str,
PolicyTypeName: str,
*,
PolicyAttributes: "builtins.list[PolicyAttribute] | None" = None,
) -> None:
"""
Creates a policy with the specified attributes for the specified load balancer.
Args:
LoadBalancerName: The name of the load balancer.
PolicyName: The name of the load balancer policy to be created. This name must be unique within the set of policies
for this load balancer.
PolicyTypeName: The name of the base policy type. To get the list of policy types, use
DescribeLoadBalancerPolicyTypes.
Keyword Args:
PolicyAttributes: The policy attributes.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
PolicyName=self.serialize(PolicyName),
PolicyTypeName=self.serialize(PolicyTypeName),
PolicyAttributes=self.serialize(PolicyAttributes),
)
self.client.create_load_balancer_policy(
**{k: v for k, v in args.items() if v is not None}
)
[docs] def describe_policies(
self, LoadBalancerName: str, *, PolicyNames: "builtins.list[str] | None" = None
) -> "builtins.list[PolicyDescription]":
"""
Describes the specified policies.
Args:
LoadBalancerName: The name of the load balancer.
Keyword Args:
PolicyNames: The names of the policies.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
PolicyNames=self.serialize(PolicyNames),
)
_response = self.client.describe_load_balancer_policies(
**{k: v for k, v in args.items() if v is not None}
)
response = DescribeLoadBalancerPoliciesOutput(**_response)
results: "builtins.list[PolicyDescription]" = None
if response is not None:
results = response.PolicyDescriptions
self.sessionize(results)
return cast("builtins.list[PolicyDescription]", results)
[docs] def delete_policy(self, LoadBalancerName: str, PolicyName: str) -> None:
"""
Deletes the specified policy from the specified load balancer. This policy must
not be enabled for any listeners.
Args:
LoadBalancerName: The name of the load balancer.
PolicyName: The name of the policy.
"""
args: dict[str, Any] = dict(
LoadBalancerName=self.serialize(LoadBalancerName),
PolicyName=self.serialize(PolicyName),
)
self.client.delete_load_balancer_policy(
**{k: v for k, v in args.items() if v is not None}
)
[docs] def describe_policy_types(
self, PolicyTypeNames: "builtins.list[str]"
) -> "builtins.list[PolicyTypeDescription]":
"""
Describes the specified load balancer policy types or all load balancer policy
types.
Args:
PolicyTypeNames: The names of the policy types. If no names are specified, describes all policy types defined by
Elastic Load Balancing.
"""
args: dict[str, Any] = dict(PolicyTypeNames=self.serialize(PolicyTypeNames))
_response = self.client.describe_load_balancer_policy_types(
**{k: v for k, v in args.items() if v is not None}
)
response = DescribeLoadBalancerPolicyTypesOutput(**_response)
results: "builtins.list[PolicyTypeDescription]" = None
if response is not None:
results = response.PolicyTypeDescriptions
self.sessionize(results)
return cast("builtins.list[PolicyTypeDescription]", results)
# ==============
# Service Models
# ==============
[docs]class ClassicELBInstance(Boto3Model):
"""
The ID of an EC2 instance.
"""
InstanceId: "str | None" = None
"""
The instance ID.
"""
[docs]class ClassicELBListener(Boto3Model):
"""
Information about a listener.
For information about the protocols and the ports supported by Elastic Load
Balancing, see
`Listeners for Your Classic Load Balancer <https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-listener-config.html>`_
in the *Classic
Load Balancers Guide*.
"""
Protocol: str
"""
The load balancer transport protocol to use for routing: HTTP, HTTPS, TCP, or SSL.
"""
LoadBalancerPort: int
"""
The port on which the load balancer is listening.
On EC2-VPC, you can specify any port from the range 1-65535. On EC2-Classic, you can
specify any port from the following list: 25, 80, 443, 465, 587, 1024-65535.
"""
InstanceProtocol: "str | None" = None
"""
The protocol to use for routing traffic to instances: HTTP, HTTPS, TCP, or SSL.
"""
InstancePort: int
"""
The port on which the instance is listening.
"""
SSLCertificateId: "str | None" = None
"""
The Amazon Resource Name (ARN) of the server certificate.
"""
[docs]class ListenerDescription(Boto3Model):
"""
The policies enabled for a listener.
"""
Listener: "ClassicELBListener | None" = None
"""
The listener.
"""
PolicyNames: "builtins.list[str] | None" = Field(default_factory=list)
"""
The policies.
If there are no policies enabled, the list is empty.
"""
[docs]class ClassicELBSourceSecurityGroup(Boto3Model):
"""
Information about a source security group.
"""
OwnerAlias: "str | None" = None
"""
The owner of the security group.
"""
GroupName: "str | None" = None
"""
The name of the security group.
"""
[docs]class AppCookieStickinessPolicy(Boto3Model):
"""
Information about a policy for application-controlled session stickiness.
"""
PolicyName: "str | None" = None
"""
The mnemonic name for the policy being created.
The name must be unique within a set of policies for this load balancer.
"""
CookieName: "str | None" = None
"""
The name of the application cookie used for stickiness.
"""
[docs]class LBCookieStickinessPolicy(Boto3Model):
"""
Information about a policy for duration-based session stickiness.
"""
PolicyName: "str | None" = None
"""
The name of the policy.
This name must be unique within the set of policies for this load balancer.
"""
CookieExpirationPeriod: "int | None" = None
"""
The time period, in seconds, after which the cookie should be considered stale.
If this parameter is not specified, the stickiness session lasts for the duration of
the browser session.
"""
[docs]class ClassicELBPolicies(Boto3Model):
"""
The policies for a load balancer.
"""
AppCookieStickinessPolicies: "builtins.list[AppCookieStickinessPolicy] | None" = (
Field(default_factory=list)
)
"""
The stickiness policies created using CreateAppCookieStickinessPolicy.
"""
LBCookieStickinessPolicies: "builtins.list[LBCookieStickinessPolicy] | None" = (
Field(default_factory=list)
)
"""
The stickiness policies created using CreateLBCookieStickinessPolicy.
"""
OtherPolicies: "builtins.list[str] | None" = Field(default_factory=list)
"""
The policies other than the stickiness policies.
"""
[docs]class BackendServerDescription(Boto3Model):
"""
Information about the configuration of an EC2 instance.
"""
InstancePort: "int | None" = None
"""
The port on which the EC2 instance is listening.
"""
PolicyNames: "builtins.list[str] | None" = Field(default_factory=list)
"""
The names of the policies enabled for the EC2 instance.
"""
[docs]class ClassicELBHealthCheck(Boto3Model):
"""
Information about a health check.
"""
Target: str
"""
The instance being checked.
The protocol is either TCP, HTTP, HTTPS, or SSL. The range of valid ports is one (1)
through 65535.
"""
Interval: int
"""
The approximate interval, in seconds, between health checks of an individual
instance.
"""
Timeout: int
"""
The amount of time, in seconds, during which no response means a failed health
check.
"""
UnhealthyThreshold: int
"""
The number of consecutive health check failures required before moving the instance
to the ``Unhealthy`` state.
"""
HealthyThreshold: int
"""
The number of consecutive health checks successes required before moving the
instance to the ``Healthy`` state.
"""
[docs]class PolicyAttribute(Boto3Model):
"""
Information about a policy attribute.
"""
AttributeName: "str | None" = None
"""
The name of the attribute.
"""
AttributeValue: "str | None" = None
"""
The value of the attribute.
"""
[docs]class ClassicELB(ClassicELBModelMixin, PrimaryBoto3Model):
"""
Information about a load balancer.
"""
manager_class: ClassVar[type[Boto3ModelManager]] = ClassicELBManager
LoadBalancerName: str
"""
The name of the load balancer.
"""
AvailabilityZones: "builtins.list[str]"
"""
The Availability Zones for the load balancer.
"""
Scheme: "str | None" = ""
"""
The type of load balancer.
Valid only for load balancers in a VPC.
"""
VPCId: str = Field(default=None, frozen=True)
"""
The ID of the VPC for the load balancer.
"""
CreatedTime: datetime = Field(default=None, frozen=True)
"""
The date and time the load balancer was created.
"""
Instances: "builtins.list[ClassicELBInstance]" = Field(
default_factory=list, frozen=True
)
"""
The IDs of the instances for the load balancer.
"""
DNSName: str = Field(default=None, frozen=True)
"""
The DNS name of the load balancer.
"""
CanonicalHostedZoneName: str = Field(default=None, frozen=True)
"""
The DNS name of the load balancer.
"""
CanonicalHostedZoneNameID: str = Field(default=None, frozen=True)
"""
The ID of the Amazon Route 53 hosted zone for the load balancer.
"""
Listeners: "builtins.list[ListenerDescription]" = Field(
default_factory=list, alias="ListenerDescriptions", frozen=True
)
"""
The listeners for the load balancer.
"""
SourceSecurityGroup: ClassicELBSourceSecurityGroup = Field(
default=None, frozen=True
)
"""
The security group for the load balancer, which you can use as part of your inbound
rules for your registered instances.
To only allow traffic from load balancers, add a security group rule that specifies
this source security group as the inbound source.
"""
Policies: "ClassicELBPolicies | None" = None
"""
The policies defined for the load balancer.
"""
BackendServerDescriptions: "builtins.list[BackendServerDescription] | None" = Field(
default_factory=list
)
"""
Information about your EC2 instances.
"""
Subnets: "builtins.list[str] | None" = Field(default_factory=list)
"""
The IDs of the subnets for the load balancer.
"""
HealthCheck: "ClassicELBHealthCheck | None" = None
"""
Information about the health checks conducted on the load balancer.
"""
SecurityGroups: "builtins.list[str] | None" = Field(default_factory=list)
"""
The security groups for the load balancer.
Valid only for load balancers in a VPC.
"""
Tags: "dict[str, str] | None" = Field(default_factory=dict)
"""
The tags associated with the load balancer.
"""
CrossZoneLoadBalancing: "bool | None" = False
"""
Whether cross-zone load balancing is enabled for the load balancer.
"""
AccessLog: "ClassicELBAccessLog | None" = None
"""
The access log settings for the load balancer.
"""
ConnectionDraining: "ClassicELBConnectionDraining | None" = None
"""
The connection draining settings for the load balancer.
"""
ConnectionSettings: "ClassicELBConnectionSettings | None" = None
"""
The connection settings for the load balancer.
"""
AdditionalAttributes: "dict[str, str] | None" = Field(default_factory=dict)
"""
Additional attributes for the load balancer.
"""
@property
def pk(self) -> str | None:
"""
Return the primary key of the model. This is the value of the
:py:attr:`LoadBalancerName` attribute.
Returns:
The primary key of the model instance.
"""
return self.LoadBalancerName
@property
def name(self) -> str | None:
"""
Return the name of the model. This is the value of the
:py:attr:`LoadBalancerName` attribute.
Returns:
The name of the model instance.
"""
return self.LoadBalancerName
def __hash__(self) -> int:
"""
Return the hash of the model.
This is the value of the
:py:attr:`LoadBalancerName` attribute.
"""
return hash(self.LoadBalancerName)
@cached_property
def vpc(self) -> "Vpc | None":
"""
Return the :py:class:`Vpc` object that this load balancer is associated with.
.. note::
The output of this property is cached on the model instance, so
calling this multiple times will not result in multiple calls to the
AWS API. If you need a fresh copy of the data, you can re-get the
model instance from the manager.
"""
try:
pk = OrderedDict(
{
"VpcId": self.VPCId,
}
)
except AttributeError:
return None
return Vpc.objects.using(self.session).get(**pk) # type: ignore[arg-type]
@cached_property
def security_groups(self) -> "list[SecurityGroup] | None":
"""
Return the security groups associated with this load balancer.
.. note::
The output of this property is cached on the model instance, so
calling this multiple times will not result in multiple calls to the
AWS API. If you need a fresh copy of the data, you can re-get the
model instance from the manager.
"""
try:
pk = OrderedDict(
{
"GroupIds": self.SecurityGroups,
}
)
except AttributeError:
return []
return SecurityGroup.objects.using(self.session).list(**pk) # type: ignore[arg-type]
@cached_property
def subnets(self) -> "list[Subnet] | None":
"""
Return the subnets associated with this load balancer.
.. note::
The output of this property is cached on the model instance, so
calling this multiple times will not result in multiple calls to the
AWS API. If you need a fresh copy of the data, you can re-get the
model instance from the manager.
"""
try:
pk = OrderedDict(
{
"SubnetIds": self.Subnets,
}
)
except AttributeError:
return []
return Subnet.objects.using(self.session).list(**pk) # type: ignore[arg-type]
@cached_property
def instances(self) -> "list[Instance] | None":
"""
Return the instances associated with this load balancer.
.. note::
The output of this property is cached on the model instance, so
calling this multiple times will not result in multiple calls to the
AWS API. If you need a fresh copy of the data, you can re-get the
model instance from the manager.
"""
try:
pk = OrderedDict(
{
"InstanceIds": [instance.InstanceId for instance in self.Instances],
}
)
except AttributeError:
return []
return Instance.objects.using(self.session).list(**pk) # type: ignore[arg-type]
[docs] def add_listeners(self, Listeners: builtins.list[ClassicELBListener]) -> "None":
"""
Add listeners to the load balancer.
Args:
Listeners: The listeners.
"""
return (
cast("ClassicELBManager", self.objects) # type: ignore[attr-defined]
.using(self.session)
.add_listeners(
cast("str", self.LoadBalancerName),
Listeners,
)
)
[docs] def remove_listeners(self, LoadBalancerPorts: builtins.list[int]) -> "None":
"""
Remove listeners from the load balancer.
Args:
LoadBalancerPorts: The client port numbers of the listeners.
"""
return (
cast("ClassicELBManager", self.objects) # type: ignore[attr-defined]
.using(self.session)
.remove_listeners(
cast("str", self.LoadBalancerName),
LoadBalancerPorts,
)
)
[docs] def set_ssl_certificate(
self, LoadBalancerPort: int, SSLCertificateId: str
) -> "None":
"""
Set the SSL certificate for a listener on the load balancer.
Args:
LoadBalancerPort: The port that uses the specified SSL certificate.
SSLCertificateId: The Amazon Resource Name (ARN) of the SSL certificate.
"""
return (
cast("ClassicELBManager", self.objects) # type: ignore[attr-defined]
.using(self.session)
.set_ssl_certificate(
cast("str", self.LoadBalancerName),
LoadBalancerPort,
SSLCertificateId,
)
)
[docs] def set_listener_policies(
self, LoadBalancerPort: int, PolicyNames: builtins.list[str]
) -> "None":
"""
Set the policies for a listener on the load balancer.
Args:
LoadBalancerPort: The external port of the load balancer.
PolicyNames: The names of the policies. This list must include all policies to be enabled. If you omit a policy that
is currently enabled, it is disabled. If the list is empty, all current policies are disabled.
"""
return (
cast("ClassicELBManager", self.objects) # type: ignore[attr-defined]
.using(self.session)
.set_listener_policies(
cast("str", self.LoadBalancerName),
LoadBalancerPort,
PolicyNames,
)
)
[docs] def set_backend_policies(
self, InstancePort: int, PolicyNames: builtins.list[str]
) -> "None":
"""
Set the policies for a backend server on the load balancer.
Args:
InstancePort: The port number associated with the EC2 instance.
PolicyNames: The names of the policies. If the list is empty, then all current polices are removed from the EC2
instance.
"""
return (
cast("ClassicELBManager", self.objects) # type: ignore[attr-defined]
.using(self.session)
.set_backend_policies(
cast("str", self.LoadBalancerName),
InstancePort,
PolicyNames,
)
)
[docs] def add_policy(
self,
PolicyName: str,
PolicyTypeName: str,
PolicyAttributes: builtins.list[PolicyAttribute] | None = None,
) -> "None":
"""
Add a policy to the load balancer.
Args:
PolicyName: The name of the load balancer policy to be created. This name must be unique within the set of policies
for this load balancer.
PolicyTypeName: The name of the base policy type. To get the list of policy types, use
DescribeLoadBalancerPolicyTypes.
Keyword Args:
PolicyAttributes: The policy attributes.
"""
return (
cast("ClassicELBManager", self.objects) # type: ignore[attr-defined]
.using(self.session)
.add_policy(
cast("str", self.LoadBalancerName),
PolicyName,
PolicyTypeName,
PolicyAttributes=PolicyAttributes,
)
)
[docs] def policies(self) -> "builtins.list[PolicyDescription]":
"""
Return the policies associated with this load balancer.
This is excludes the StickinessPolicy and the LBCookieStickinessPolicy. You can
look directly on this object for those policies.
"""
return (
cast("ClassicELBManager", self.objects) # type: ignore[attr-defined]
.using(self.session)
.describe_policies()
)
[docs] def delete_policy(self, PolicyName: str) -> "None":
"""
Delete a policy from the load balancer.
Args:
PolicyName: The name of the policy.
"""
return (
cast("ClassicELBManager", self.objects) # type: ignore[attr-defined]
.using(self.session)
.delete_policy(
cast("str", self.LoadBalancerName),
PolicyName,
)
)
[docs] def add_instances(
self, Instances: builtins.list[ClassicELBInstance]
) -> "builtins.list[ClassicELBInstance]":
"""
Add instances to the load balancer.
Args:
Instances: The IDs of the instances.
"""
return (
cast("ClassicELBManager", self.objects) # type: ignore[attr-defined]
.using(self.session)
.register_instances(
cast("str", self.LoadBalancerName),
Instances,
)
)
[docs] def remove_instances(
self, Instances: builtins.list[ClassicELBInstance]
) -> "builtins.list[ClassicELBInstance]":
"""
Remove instances from the load balancer.
Args:
Instances: The IDs of the instances.
"""
return (
cast("ClassicELBManager", self.objects) # type: ignore[attr-defined]
.using(self.session)
.deregister_instances(
cast("str", self.LoadBalancerName),
Instances,
)
)
# =======================
# Request/Response Models
# =======================
[docs]class DeleteAccessPointOutput(Boto3Model):
"""
Contains the output of DeleteLoadBalancer.
"""
[docs]class DescribeAccessPointsOutput(Boto3Model):
"""
Contains the parameters for DescribeLoadBalancers.
"""
LoadBalancerDescriptions: "builtins.list[ClassicELB] | None" = Field(
default_factory=list
)
"""
Information about the load balancers.
"""
NextMarker: "str | None" = None
"""
The marker to use when requesting the next set of results.
If there are no additional results, the string is empty.
"""
[docs]class ClassicELBTagDescription(TagsDictMixin, Boto3Model):
"""
The tags associated with a load balancer.
"""
tag_class: ClassVar[type[Boto3Model]] = Tag
LoadBalancerName: "str | None" = None
"""
The name of the load balancer.
"""
Tags: "builtins.list[Tag] | None" = Field(default_factory=list)
"""
The tags.
"""
[docs]class TagKeyOnly(Boto3Model):
"""
The key of a tag.
"""
Key: "str | None" = None
"""
The name of the key.
"""
[docs]class AddAvailabilityZonesOutput(Boto3Model):
"""
Contains the output of EnableAvailabilityZonesForLoadBalancer.
"""
AvailabilityZones: "builtins.list[str] | None" = Field(default_factory=list)
"""
The updated list of Availability Zones for the load balancer.
"""
[docs]class RemoveAvailabilityZonesOutput(Boto3Model):
"""
Contains the output for DisableAvailabilityZonesForLoadBalancer.
"""
AvailabilityZones: "builtins.list[str] | None" = Field(default_factory=list)
"""
The remaining Availability Zones for the load balancer.
"""
[docs]class RegisterEndPointsOutput(Boto3Model):
"""
Contains the output of RegisterInstancesWithLoadBalancer.
"""
Instances: "builtins.list[ClassicELBInstance] | None" = Field(default_factory=list)
"""
The updated list of instances for the load balancer.
"""
[docs]class ClassicELBInstanceState(Boto3Model):
"""
Information about the state of an EC2 instance.
"""
InstanceId: "str | None" = None
"""
The ID of the instance.
"""
State: "str | None" = None
"""
The current state of the instance.
"""
ReasonCode: "str | None" = None
"""
Information about the cause of ``OutOfService`` instances.
Specifically, whether the cause is Elastic Load Balancing or the instance.
"""
Description: "str | None" = None
"""
A description of the instance state.
This string can contain one or more of the following messages.
"""
[docs]class DescribeEndPointStateOutput(Boto3Model):
"""
Contains the output for DescribeInstanceHealth.
"""
InstanceStates: "builtins.list[ClassicELBInstanceState] | None" = Field(
default_factory=list
)
"""
Information about the health of the instances.
"""
[docs]class DeregisterEndPointsOutput(Boto3Model):
"""
Contains the output of DeregisterInstancesFromLoadBalancer.
"""
Instances: "builtins.list[ClassicELBInstance] | None" = Field(default_factory=list)
"""
The remaining instances registered with the load balancer.
"""
[docs]class CreateLoadBalancerListenerOutput(Boto3Model):
"""
Contains the parameters for CreateLoadBalancerListener.
"""
[docs]class DeleteLoadBalancerListenerOutput(Boto3Model):
"""
Contains the output of DeleteLoadBalancerListeners.
"""
[docs]class ClassicELBCrossZoneLoadBalancing(Boto3Model):
"""
Information about the ``CrossZoneLoadBalancing`` attribute.
"""
Enabled: bool
"""
Specifies whether cross-zone load balancing is enabled for the load balancer.
"""
[docs]class ClassicELBAccessLog(Boto3Model):
"""
Information about the ``AccessLog`` attribute.
"""
Enabled: bool
"""
Specifies whether access logs are enabled for the load balancer.
"""
S3BucketName: "str | None" = None
"""
The name of the Amazon S3 bucket where the access logs are stored.
"""
EmitInterval: "int | None" = None
"""
The interval for publishing the access logs.
You can specify an interval of either 5 minutes or 60 minutes.
"""
S3BucketPrefix: "str | None" = None
"""
The logical hierarchy you created for your Amazon S3 bucket, for example ``my-
bucket-prefix/prod``.
If the prefix is not provided, the log is placed at the root level of the bucket.
"""
[docs]class ClassicELBConnectionDraining(Boto3Model):
"""
Information about the ``ConnectionDraining`` attribute.
"""
Enabled: bool
"""
Specifies whether connection draining is enabled for the load balancer.
"""
Timeout: "int | None" = None
"""
The maximum time, in seconds, to keep the existing connections open before
deregistering the instances.
"""
[docs]class ClassicELBConnectionSettings(Boto3Model):
"""
Information about the ``ConnectionSettings`` attribute.
"""
IdleTimeout: int
"""
The time, in seconds, that the connection is allowed to be idle (no data has been
sent over the connection) before it is closed by the load balancer.
"""
[docs]class AdditionalAttribute(Boto3Model):
"""
Information about additional load balancer attributes.
"""
Key: "str | None" = None
"""
The name of the attribute.
"""
Value: "str | None" = None
"""
This value of the attribute.
"""
[docs]class ClassicELBLoadBalancerAttributes(Boto3Model):
"""
The attributes for a load balancer.
"""
CrossZoneLoadBalancing: "ClassicELBCrossZoneLoadBalancing | None" = None
"""
If enabled, the load balancer routes the request traffic evenly across all instances
regardless of the Availability Zones.
"""
AccessLog: "ClassicELBAccessLog | None" = None
"""
If enabled, the load balancer captures detailed information of all requests and
delivers the information to the Amazon S3 bucket that you specify.
"""
ConnectionDraining: "ClassicELBConnectionDraining | None" = None
"""
If enabled, the load balancer allows existing requests to complete before the load
balancer shifts traffic away from a deregistered or unhealthy instance.
"""
ConnectionSettings: "ClassicELBConnectionSettings | None" = None
"""
If enabled, the load balancer allows the connections to remain idle (no data is sent
over the connection) for the specified duration.
"""
AdditionalAttributes: "builtins.list[AdditionalAttribute] | None" = Field(
default_factory=list
)
"""
Any additional attributes.
"""
[docs]class DescribeClassicELBAttributesResponse(Boto3Model):
"""
Contains the output of DescribeLoadBalancerAttributes.
"""
LoadBalancerAttributes: "ClassicELBLoadBalancerAttributes | None" = None
"""
Information about the load balancer attributes.
"""
[docs]class ModifyLoadBalancerAttributesOutput(Boto3Model):
"""
Contains the output of ModifyLoadBalancerAttributes.
"""
LoadBalancerName: "str | None" = None
"""
The name of the load balancer.
"""
LoadBalancerAttributes: "ClassicELBLoadBalancerAttributes | None" = None
"""
Information about the load balancer attributes.
"""
[docs]class DetachLoadBalancerFromSubnetsOutput(Boto3Model):
"""
Contains the output of DetachLoadBalancerFromSubnets.
"""
Subnets: "builtins.list[str] | None" = Field(default_factory=list)
"""
The IDs of the remaining subnets for the load balancer.
"""
[docs]class AttachLoadBalancerToSubnetsOutput(Boto3Model):
"""
Contains the output of AttachLoadBalancerToSubnets.
"""
Subnets: "builtins.list[str] | None" = Field(default_factory=list)
"""
The IDs of the subnets attached to the load balancer.
"""
[docs]class ApplySecurityGroupsToLoadBalancerOutput(Boto3Model):
"""
Contains the output of ApplySecurityGroupsToLoadBalancer.
"""
SecurityGroups: "builtins.list[str] | None" = Field(default_factory=list)
"""
The IDs of the security groups associated with the load balancer.
"""
[docs]class SetLoadBalancerPoliciesOfListenerOutput(Boto3Model):
"""
Contains the output of SetLoadBalancePoliciesOfListener.
"""
[docs]class SetLoadBalancerPoliciesForBackendServerOutput(Boto3Model):
"""
Contains the output of SetLoadBalancerPoliciesForBackendServer.
"""
[docs]class CreateLoadBalancerPolicyOutput(Boto3Model):
"""
Contains the output of CreateLoadBalancerPolicy.
"""
[docs]class PolicyAttributeDescription(Boto3Model):
"""
Information about a policy attribute.
"""
AttributeName: "str | None" = None
"""
The name of the attribute.
"""
AttributeValue: "str | None" = None
"""
The value of the attribute.
"""
[docs]class PolicyDescription(Boto3Model):
"""
Information about a policy.
"""
PolicyName: "str | None" = None
"""
The name of the policy.
"""
PolicyTypeName: "str | None" = None
"""
The name of the policy type.
"""
PolicyAttributeDescriptions: "builtins.list[PolicyAttributeDescription] | None" = (
Field(default_factory=list)
)
"""
The policy attributes.
"""
[docs]class DescribeLoadBalancerPoliciesOutput(Boto3Model):
"""
Contains the output of DescribeLoadBalancerPolicies.
"""
PolicyDescriptions: "builtins.list[PolicyDescription] | None" = Field(
default_factory=list
)
"""
Information about the policies.
"""
[docs]class DeleteLoadBalancerPolicyOutput(Boto3Model):
"""
Contains the output of DeleteLoadBalancerPolicy.
"""
[docs]class PolicyAttributeTypeDescription(Boto3Model):
"""
Information about a policy attribute type.
"""
AttributeName: "str | None" = None
"""
The name of the attribute.
"""
AttributeType: "str | None" = None
"""
The type of the attribute.
For example, ``Boolean`` or ``Integer``.
"""
Description: "str | None" = None
"""
A description of the attribute.
"""
DefaultValue: "str | None" = None
"""
The default value of the attribute, if applicable.
"""
Cardinality: "str | None" = None
"""
The cardinality of the attribute.
"""
[docs]class PolicyTypeDescription(Boto3Model):
"""
Information about a policy type.
"""
PolicyTypeName: "str | None" = None
"""
The name of the policy type.
"""
Description: "str | None" = None
"""
A description of the policy type.
"""
PolicyAttributeTypeDescriptions: "builtins.list[PolicyAttributeTypeDescription] | None" = Field(
default_factory=list
)
"""
The description of the policy attributes associated with the policies defined by
Elastic Load Balancing.
"""
[docs]class DescribeLoadBalancerPolicyTypesOutput(Boto3Model):
"""
Contains the output of DescribeLoadBalancerPolicyTypes.
"""
PolicyTypeDescriptions: "builtins.list[PolicyTypeDescription] | None" = Field(
default_factory=list
)
"""
Information about the policy types.
"""