Skip to content

create_load_balancer async

create_load_balancer(
    load_balancer_name: AccessPointName,
    listeners: Listeners,
    *,
    config_overrides: Optional[AsyncElasticLoadBalancingClientConfig] = None,
    availability_zones: Optional[AvailabilityZones] = None,
    subnets: Optional[Subnets] = None,
    security_groups: Optional[SecurityGroups] = None,
    scheme: Optional[LoadBalancerScheme] = None,
    tags: Optional[TagList] = None,
) -> CreateAccessPointOutput

Creates a Classic Load Balancer.

You can add listeners, security groups, subnets, and tags when you create your load balancer, or you can add them later using CreateLoadBalancerListeners, ApplySecurityGroupsToLoadBalancer, AttachLoadBalancerToSubnets, and AddTags.

To describe your current load balancers, see DescribeLoadBalancers. When you are finished with a load balancer, you can delete it using DeleteLoadBalancer.

You can create up to 20 load balancers per region per account. You can request an increase for the number of load balancers for your account. For more information, see Limits for Your Classic Load Balancer in the Classic Load Balancers Guide.

Parameters:

  • load_balancer_name (AccessPointName) –

    The name of the load balancer.

    This name must be unique within your set of load balancers for the region, must have a maximum of 32 characters, must contain only alphanumeric characters or hyphens, and cannot begin or end with a hyphen.

  • listeners (Listeners) –

    The listeners.

    For more information, see Listeners for Your Classic Load Balancer in the Classic Load Balancers Guide.

  • availability_zones (Optional[AvailabilityZones], default: None ) –

    One or more Availability Zones from the same region as the load balancer.

    You must specify at least one Availability Zone.

    You can add more Availability Zones after you create the load balancer using EnableAvailabilityZonesForLoadBalancer.

  • subnets (Optional[Subnets], default: None ) –

    The IDs of the subnets in your VPC to attach to the load balancer. Specify one subnet per Availability Zone specified in AvailabilityZones.

  • security_groups (Optional[SecurityGroups], default: None ) –

    The IDs of the security groups to assign to the load balancer.

  • scheme (Optional[LoadBalancerScheme], default: None ) –

    The type of a load balancer. Valid only for load balancers in a VPC.

    By default, Elastic Load Balancing creates an Internet-facing load balancer with a DNS name that resolves to public IP addresses. For more information about Internet-facing and Internal load balancers, see Load Balancer Scheme in the Elastic Load Balancing User Guide.

    Specify internal to create a load balancer with a DNS name that resolves to private IP addresses.

  • tags (Optional[TagList], default: None ) –

    A list of tags to assign to the load balancer.

    For more information about tagging your load balancer, see Tag Your Classic Load Balancer in the Classic Load Balancers Guide.

Raises:

Examples:

To create an HTTP load balancer in a VPC This example creates a load balancer with an HTTP listener in a VPC.

>>> await client.create_load_balancer(load_balancer_name='my-load-balancer', listeners=[{'Protocol': 'HTTP', 'LoadBalancerPort': 80, 'InstanceProtocol': 'HTTP', 'InstancePort': 80}], subnets=['subnet-15aaab61'], security_groups=['sg-a61988c3'])
To create an HTTP load balancer in EC2-Classic
This example creates a load balancer with an HTTP listener in EC2-Classic.
>>> await client.create_load_balancer(load_balancer_name='my-load-balancer', listeners=[{'Protocol': 'HTTP', 'LoadBalancerPort': 80, 'InstanceProtocol': 'HTTP', 'InstancePort': 80}], availability_zones=['us-west-2a'])
To create an HTTPS load balancer in a VPC
This example creates a load balancer with an HTTPS listener in a VPC.
>>> await client.create_load_balancer(load_balancer_name='my-load-balancer', listeners=[{'Protocol': 'HTTP', 'LoadBalancerPort': 80, 'InstanceProtocol': 'HTTP', 'InstancePort': 80}, {'Protocol': 'HTTPS', 'LoadBalancerPort': 443, 'InstanceProtocol': 'HTTP', 'InstancePort': 80, 'SSLCertificateId': 'arn:aws:iam::123456789012:server-certificate/my-server-cert'}], subnets=['subnet-15aaab61'], security_groups=['sg-a61988c3'])
To create an HTTPS load balancer in EC2-Classic
This example creates a load balancer with an HTTPS listener in EC2-Classic.
>>> await client.create_load_balancer(load_balancer_name='my-load-balancer', listeners=[{'Protocol': 'HTTP', 'LoadBalancerPort': 80, 'InstanceProtocol': 'HTTP', 'InstancePort': 80}, {'Protocol': 'HTTPS', 'LoadBalancerPort': 443, 'InstanceProtocol': 'HTTP', 'InstancePort': 80, 'SSLCertificateId': 'arn:aws:iam::123456789012:server-certificate/my-server-cert'}], availability_zones=['us-west-2a'])
To create an internal load balancer
This example creates an internal load balancer with an HTTP listener in a VPC.
>>> await client.create_load_balancer(load_balancer_name='my-load-balancer', listeners=[{'Protocol': 'HTTP', 'LoadBalancerPort': 80, 'InstanceProtocol': 'HTTP', 'InstancePort': 80}], subnets=['subnet-15aaab61'], security_groups=['sg-a61988c3'], scheme='internal')
Source code in docs_src/capo_elastic_load_balancing/_services/async_elastic_load_balancing.py
async def create_load_balancer(
    self,
    load_balancer_name: "capo_elastic_load_balancing.types.access_point_name.AccessPointName",
    listeners: "capo_elastic_load_balancing.types.listeners.Listeners",
    *,
    config_overrides: Optional[AsyncElasticLoadBalancingClientConfig] = None,
    availability_zones: Optional[
        "capo_elastic_load_balancing.types.availability_zones.AvailabilityZones"
    ] = None,
    subnets: Optional["capo_elastic_load_balancing.types.subnets.Subnets"] = None,
    security_groups: Optional[
        "capo_elastic_load_balancing.types.security_groups.SecurityGroups"
    ] = None,
    scheme: Optional[
        "capo_elastic_load_balancing.types.load_balancer_scheme.LoadBalancerScheme"
    ] = None,
    tags: Optional["capo_elastic_load_balancing.types.tag_list.TagList"] = None,
) -> "capo_elastic_load_balancing.types.create_access_point_output.CreateAccessPointOutput":
    """<p>Creates a Classic Load Balancer.</p> <p>You can add listeners, security groups, subnets, and tags when you create your load balancer, or you can add them later using <a>CreateLoadBalancerListeners</a>, <a>ApplySecurityGroupsToLoadBalancer</a>, <a>AttachLoadBalancerToSubnets</a>, and <a>AddTags</a>.</p> <p>To describe your current load balancers, see <a>DescribeLoadBalancers</a>. When you are finished with a load balancer, you can delete it using <a>DeleteLoadBalancer</a>.</p> <p>You can create up to 20 load balancers per region per account. You can request an increase for the number of load balancers for your account. For more information, see <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-limits.html">Limits for Your Classic Load Balancer</a> in the <i>Classic Load Balancers Guide</i>.</p>

    Args:
        load_balancer_name: <p>The name of the load balancer.</p> <p>This name must be unique within your set of load balancers for the region, must have a maximum of 32 characters, must contain only alphanumeric characters or hyphens, and cannot begin or end with a hyphen.</p>
        listeners: <p>The listeners.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-listener-config.html">Listeners for Your Classic Load Balancer</a> in the <i>Classic Load Balancers Guide</i>.</p>
        availability_zones: <p>One or more Availability Zones from the same region as the load balancer.</p> <p>You must specify at least one Availability Zone.</p> <p>You can add more Availability Zones after you create the load balancer using <a>EnableAvailabilityZonesForLoadBalancer</a>.</p>
        subnets: <p>The IDs of the subnets in your VPC to attach to the load balancer. Specify one subnet per Availability Zone specified in <code>AvailabilityZones</code>.</p>
        security_groups: <p>The IDs of the security groups to assign to the load balancer.</p>
        scheme: <p>The type of a load balancer. Valid only for load balancers in a VPC.</p> <p>By default, Elastic Load Balancing creates an Internet-facing load balancer with a DNS name that resolves to public IP addresses. For more information about Internet-facing and Internal load balancers, see <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/how-elastic-load-balancing-works.html#load-balancer-scheme">Load Balancer Scheme</a> in the <i>Elastic Load Balancing User Guide</i>.</p> <p>Specify <code>internal</code> to create a load balancer with a DNS name that resolves to private IP addresses.</p>
        tags: <p>A list of tags to assign to the load balancer.</p> <p>For more information about tagging your load balancer, see <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/add-remove-tags.html">Tag Your Classic Load Balancer</a> in the <i>Classic Load Balancers Guide</i>.</p>

    Raises:
        capo_elastic_load_balancing.errors.certificate_not_found_exception.CertificateNotFoundException: <p>The specified ARN does not refer to a valid SSL certificate in AWS Identity and Access Management (IAM) or AWS Certificate Manager (ACM). Note that if you recently uploaded the certificate to IAM, this error might indicate that the certificate is not fully available yet.</p>
        capo_elastic_load_balancing.errors.duplicate_access_point_name_exception.DuplicateAccessPointNameException: <p>The specified load balancer name already exists for this account.</p>
        capo_elastic_load_balancing.errors.duplicate_tag_keys_exception.DuplicateTagKeysException: <p>A tag key was specified more than once.</p>
        capo_elastic_load_balancing.errors.invalid_configuration_request_exception.InvalidConfigurationRequestException: <p>The requested configuration change is not valid.</p>
        capo_elastic_load_balancing.errors.invalid_scheme_exception.InvalidSchemeException: <p>The specified value for the schema is not valid. You can only specify a scheme for load balancers in a VPC.</p>
        capo_elastic_load_balancing.errors.invalid_security_group_exception.InvalidSecurityGroupException: <p>One or more of the specified security groups do not exist.</p>
        capo_elastic_load_balancing.errors.invalid_subnet_exception.InvalidSubnetException: <p>The specified VPC has no associated Internet gateway.</p>
        capo_elastic_load_balancing.errors.operation_not_permitted_exception.OperationNotPermittedException: <p>This operation is not allowed.</p>
        capo_elastic_load_balancing.errors.subnet_not_found_exception.SubnetNotFoundException: <p>One or more of the specified subnets do not exist.</p>
        capo_elastic_load_balancing.errors.too_many_access_points_exception.TooManyAccessPointsException: <p>The quota for the number of load balancers has been reached.</p>
        capo_elastic_load_balancing.errors.too_many_tags_exception.TooManyTagsException: <p>The quota for the number of tags that can be assigned to a load balancer has been reached.</p>
        capo_elastic_load_balancing.errors.unsupported_protocol_exception.UnsupportedProtocolException: <p>The specified protocol or signature version is not supported.</p>
        capo_elastic_load_balancing.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To create an HTTP load balancer in a VPC
        This example creates a load balancer with an HTTP listener in a VPC.

        >>> await client.create_load_balancer(load_balancer_name='my-load-balancer', listeners=[{'Protocol': 'HTTP', 'LoadBalancerPort': 80, 'InstanceProtocol': 'HTTP', 'InstancePort': 80}], subnets=['subnet-15aaab61'], security_groups=['sg-a61988c3'])
        To create an HTTP load balancer in EC2-Classic
        This example creates a load balancer with an HTTP listener in EC2-Classic.

        >>> await client.create_load_balancer(load_balancer_name='my-load-balancer', listeners=[{'Protocol': 'HTTP', 'LoadBalancerPort': 80, 'InstanceProtocol': 'HTTP', 'InstancePort': 80}], availability_zones=['us-west-2a'])
        To create an HTTPS load balancer in a VPC
        This example creates a load balancer with an HTTPS listener in a VPC.

        >>> await client.create_load_balancer(load_balancer_name='my-load-balancer', listeners=[{'Protocol': 'HTTP', 'LoadBalancerPort': 80, 'InstanceProtocol': 'HTTP', 'InstancePort': 80}, {'Protocol': 'HTTPS', 'LoadBalancerPort': 443, 'InstanceProtocol': 'HTTP', 'InstancePort': 80, 'SSLCertificateId': 'arn:aws:iam::123456789012:server-certificate/my-server-cert'}], subnets=['subnet-15aaab61'], security_groups=['sg-a61988c3'])
        To create an HTTPS load balancer in EC2-Classic
        This example creates a load balancer with an HTTPS listener in EC2-Classic.

        >>> await client.create_load_balancer(load_balancer_name='my-load-balancer', listeners=[{'Protocol': 'HTTP', 'LoadBalancerPort': 80, 'InstanceProtocol': 'HTTP', 'InstancePort': 80}, {'Protocol': 'HTTPS', 'LoadBalancerPort': 443, 'InstanceProtocol': 'HTTP', 'InstancePort': 80, 'SSLCertificateId': 'arn:aws:iam::123456789012:server-certificate/my-server-cert'}], availability_zones=['us-west-2a'])
        To create an internal load balancer
        This example creates an internal load balancer with an HTTP listener in a VPC.

        >>> await client.create_load_balancer(load_balancer_name='my-load-balancer', listeners=[{'Protocol': 'HTTP', 'LoadBalancerPort': 80, 'InstanceProtocol': 'HTTP', 'InstancePort': 80}], subnets=['subnet-15aaab61'], security_groups=['sg-a61988c3'], scheme='internal')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_elastic_load_balancing.types.create_access_point_input.CreateAccessPointInput]",
    ) -> AsyncOperationResponse[
        "capo_elastic_load_balancing.types.create_access_point_output.CreateAccessPointOutput"
    ]:
        import capo_elastic_load_balancing._operations.elastic_load_balancing_v7.create_load_balancer

        (
            output,
            http_response,
        ) = await capo_elastic_load_balancing._operations.elastic_load_balancing_v7.create_load_balancer.async_create_load_balancer(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateLoadBalancer")
    )
    input_: capo_elastic_load_balancing.types.create_access_point_input.CreateAccessPointInput = {
        "load_balancer_name": load_balancer_name,
        "listeners": listeners,
    }
    if availability_zones is not None:
        input_["availability_zones"] = availability_zones
    if subnets is not None:
        input_["subnets"] = subnets
    if security_groups is not None:
        input_["security_groups"] = security_groups
    if scheme is not None:
        input_["scheme"] = scheme
    if tags is not None:
        input_["tags"] = tags

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output