Skip to content

create_load_balancer async

create_load_balancer(
    *,
    config_overrides: Optional[AsyncElasticLoadBalancingv2ClientConfig] = None,
    name: Optional[LoadBalancerName] = None,
    subnets: Optional[Subnets] = None,
    subnet_mappings: Optional[SubnetMappings] = None,
    security_groups: Optional[SecurityGroups] = None,
    scheme: Optional[LoadBalancerSchemeEnum] = None,
    tags: Optional[TagList] = None,
    type: Optional[LoadBalancerTypeEnum] = None,
    ip_address_type: Optional[IpAddressType] = None,
    customer_owned_ipv4_pool: Optional[CustomerOwnedIpv4Pool] = None,
    enable_prefix_for_ipv6_source_nat: Optional[
        EnablePrefixForIpv6SourceNatEnum
    ] = None,
    ipam_pools: Optional[IpamPools] = None,
) -> CreateLoadBalancerOutput

Creates an Application Load Balancer, Network Load Balancer, or Gateway Load Balancer.

For more information, see the following:

This operation is idempotent, which means that it completes at most one time. If you attempt to create multiple load balancers with the same settings, each call succeeds.

Parameters:

  • name (Optional[LoadBalancerName], default: None ) –

    The name of the load balancer.

    This name must be unique per region per account, can have a maximum of 32 characters, must contain only alphanumeric characters or hyphens, must not begin or end with a hyphen, and must not begin with "internal-".

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

    The IDs of the subnets. You can specify only one subnet per Availability Zone. You must specify either subnets or subnet mappings, but not both. To specify an Elastic IP address, specify subnet mappings instead of subnets.

    [Application Load Balancers] You must specify subnets from at least two Availability Zones.

    [Application Load Balancers on Outposts] You must specify one Outpost subnet.

    [Application Load Balancers on Local Zones] You can specify subnets from one or more Local Zones.

    [Network Load Balancers and Gateway Load Balancers] You can specify subnets from one or more Availability Zones.

  • subnet_mappings (Optional[SubnetMappings], default: None ) –

    The IDs of the subnets. You can specify only one subnet per Availability Zone. You must specify either subnets or subnet mappings, but not both.

    [Application Load Balancers] You must specify subnets from at least two Availability Zones. You can't specify Elastic IP addresses for your subnets.

    [Application Load Balancers on Outposts] You must specify one Outpost subnet.

    [Application Load Balancers on Local Zones] You can specify subnets from one or more Local Zones.

    [Network Load Balancers] You can specify subnets from one or more Availability Zones. You can specify one Elastic IP address per subnet if you need static IP addresses for your internet-facing load balancer. For internal load balancers, you can specify one private IP address per subnet from the IPv4 range of the subnet. For internet-facing load balancer, you can specify one IPv6 address per subnet.

    [Gateway Load Balancers] You can specify subnets from one or more Availability Zones. You can't specify Elastic IP addresses for your subnets.

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

    [Application Load Balancers and Network Load Balancers] The IDs of the security groups for the load balancer.

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

    The nodes of an Internet-facing load balancer have public IP addresses. The DNS name of an Internet-facing load balancer is publicly resolvable to the public IP addresses of the nodes. Therefore, Internet-facing load balancers can route requests from clients over the internet.

    The nodes of an internal load balancer have only private IP addresses. The DNS name of an internal load balancer is publicly resolvable to the private IP addresses of the nodes. Therefore, internal load balancers can route requests only from clients with access to the VPC for the load balancer.

    The default is an Internet-facing load balancer.

    You can't specify a scheme for a Gateway Load Balancer.

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

    The tags to assign to the load balancer.

  • type (Optional[LoadBalancerTypeEnum], default: None ) –

    The type of load balancer. The default is application.

  • ip_address_type (Optional[IpAddressType], default: None ) –

    The IP address type. Internal load balancers must use ipv4.

    [Application Load Balancers] The possible values are ipv4 (IPv4 addresses), dualstack (IPv4 and IPv6 addresses), and dualstack-without-public-ipv4 (public IPv6 addresses and private IPv4 and IPv6 addresses).

    [Network Load Balancers and Gateway Load Balancers] The possible values are ipv4 (IPv4 addresses) and dualstack (IPv4 and IPv6 addresses).

  • customer_owned_ipv4_pool (Optional[CustomerOwnedIpv4Pool], default: None ) –

    [Application Load Balancers on Outposts] The ID of the customer-owned address pool (CoIP pool).

  • enable_prefix_for_ipv6_source_nat (Optional[EnablePrefixForIpv6SourceNatEnum], default: None ) –

    [Network Load Balancers with UDP listeners] Indicates whether to use an IPv6 prefix from each subnet for source NAT. The IP address type must be dualstack. The default value is off.

  • ipam_pools (Optional[IpamPools], default: None ) –

    [Application Load Balancers] The IPAM pools to use with the load balancer.

Raises:

Examples:

To create an Internet-facing load balancer This example creates an Internet-facing load balancer and enables the Availability Zones for the specified subnets.

>>> await client.create_load_balancer(name='my-load-balancer', subnets=['subnet-b7d581c0', 'subnet-8360a9e7'])
To create an internal load balancer
This example creates an internal load balancer and enables the Availability Zones for the specified subnets.
>>> await client.create_load_balancer(name='my-internal-load-balancer', subnets=['subnet-b7d581c0', 'subnet-8360a9e7'], security_groups=[], scheme='internal')
Source code in docs_src/capo_elastic_load_balancing_v2/_services/async_elastic_load_balancingv2.py
async def create_load_balancer(
    self,
    *,
    config_overrides: Optional[AsyncElasticLoadBalancingv2ClientConfig] = None,
    name: Optional[
        "capo_elastic_load_balancing_v2.types.load_balancer_name.LoadBalancerName"
    ] = None,
    subnets: Optional[
        "capo_elastic_load_balancing_v2.types.subnets.Subnets"
    ] = None,
    subnet_mappings: Optional[
        "capo_elastic_load_balancing_v2.types.subnet_mappings.SubnetMappings"
    ] = None,
    security_groups: Optional[
        "capo_elastic_load_balancing_v2.types.security_groups.SecurityGroups"
    ] = None,
    scheme: Optional[
        "capo_elastic_load_balancing_v2.types.load_balancer_scheme_enum.LoadBalancerSchemeEnum"
    ] = None,
    tags: Optional["capo_elastic_load_balancing_v2.types.tag_list.TagList"] = None,
    type: Optional[
        "capo_elastic_load_balancing_v2.types.load_balancer_type_enum.LoadBalancerTypeEnum"
    ] = None,
    ip_address_type: Optional[
        "capo_elastic_load_balancing_v2.types.ip_address_type.IpAddressType"
    ] = None,
    customer_owned_ipv4_pool: Optional[
        "capo_elastic_load_balancing_v2.types.customer_owned_ipv4_pool.CustomerOwnedIpv4Pool"
    ] = None,
    enable_prefix_for_ipv6_source_nat: Optional[
        "capo_elastic_load_balancing_v2.types.enable_prefix_for_ipv6_source_nat_enum.EnablePrefixForIpv6SourceNatEnum"
    ] = None,
    ipam_pools: Optional[
        "capo_elastic_load_balancing_v2.types.ipam_pools.IpamPools"
    ] = None,
) -> "capo_elastic_load_balancing_v2.types.create_load_balancer_output.CreateLoadBalancerOutput":
    """<p>Creates an Application Load Balancer, Network Load Balancer, or Gateway Load Balancer.</p> <p>For more information, see the following:</p> <ul> <li> <p> <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/application-load-balancers.html">Application Load Balancers</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/network/network-load-balancers.html">Network Load Balancers</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/gateway/gateway-load-balancers.html">Gateway Load Balancers</a> </p> </li> </ul> <p>This operation is idempotent, which means that it completes at most one time. If you attempt to create multiple load balancers with the same settings, each call succeeds.</p>

    Args:
        name: <p>The name of the load balancer.</p> <p>This name must be unique per region per account, can have a maximum of 32 characters, must contain only alphanumeric characters or hyphens, must not begin or end with a hyphen, and must not begin with "internal-".</p>
        subnets: <p>The IDs of the subnets. You can specify only one subnet per Availability Zone. You must specify either subnets or subnet mappings, but not both. To specify an Elastic IP address, specify subnet mappings instead of subnets.</p> <p>[Application Load Balancers] You must specify subnets from at least two Availability Zones.</p> <p>[Application Load Balancers on Outposts] You must specify one Outpost subnet.</p> <p>[Application Load Balancers on Local Zones] You can specify subnets from one or more Local Zones.</p> <p>[Network Load Balancers and Gateway Load Balancers] You can specify subnets from one or more Availability Zones.</p>
        subnet_mappings: <p>The IDs of the subnets. You can specify only one subnet per Availability Zone. You must specify either subnets or subnet mappings, but not both.</p> <p>[Application Load Balancers] You must specify subnets from at least two Availability Zones. You can't specify Elastic IP addresses for your subnets.</p> <p>[Application Load Balancers on Outposts] You must specify one Outpost subnet.</p> <p>[Application Load Balancers on Local Zones] You can specify subnets from one or more Local Zones.</p> <p>[Network Load Balancers] You can specify subnets from one or more Availability Zones. You can specify one Elastic IP address per subnet if you need static IP addresses for your internet-facing load balancer. For internal load balancers, you can specify one private IP address per subnet from the IPv4 range of the subnet. For internet-facing load balancer, you can specify one IPv6 address per subnet.</p> <p>[Gateway Load Balancers] You can specify subnets from one or more Availability Zones. You can't specify Elastic IP addresses for your subnets.</p>
        security_groups: <p>[Application Load Balancers and Network Load Balancers] The IDs of the security groups for the load balancer.</p>
        scheme: <p>The nodes of an Internet-facing load balancer have public IP addresses. The DNS name of an Internet-facing load balancer is publicly resolvable to the public IP addresses of the nodes. Therefore, Internet-facing load balancers can route requests from clients over the internet.</p> <p>The nodes of an internal load balancer have only private IP addresses. The DNS name of an internal load balancer is publicly resolvable to the private IP addresses of the nodes. Therefore, internal load balancers can route requests only from clients with access to the VPC for the load balancer.</p> <p>The default is an Internet-facing load balancer.</p> <p>You can't specify a scheme for a Gateway Load Balancer.</p>
        tags: <p>The tags to assign to the load balancer.</p>
        type: <p>The type of load balancer. The default is <code>application</code>.</p>
        ip_address_type: <p>The IP address type. Internal load balancers must use <code>ipv4</code>.</p> <p>[Application Load Balancers] The possible values are <code>ipv4</code> (IPv4 addresses), <code>dualstack</code> (IPv4 and IPv6 addresses), and <code>dualstack-without-public-ipv4</code> (public IPv6 addresses and private IPv4 and IPv6 addresses).</p> <p>[Network Load Balancers and Gateway Load Balancers] The possible values are <code>ipv4</code> (IPv4 addresses) and <code>dualstack</code> (IPv4 and IPv6 addresses).</p>
        customer_owned_ipv4_pool: <p>[Application Load Balancers on Outposts] The ID of the customer-owned address pool (CoIP pool).</p>
        enable_prefix_for_ipv6_source_nat: <p>[Network Load Balancers with UDP listeners] Indicates whether to use an IPv6 prefix from each subnet for source NAT. The IP address type must be <code>dualstack</code>. The default value is <code>off</code>.</p>
        ipam_pools: <p>[Application Load Balancers] The IPAM pools to use with the load balancer.</p>

    Raises:
        capo_elastic_load_balancing_v2.errors.allocation_id_not_found_exception.AllocationIdNotFoundException: <p>The specified allocation ID does not exist.</p>
        capo_elastic_load_balancing_v2.errors.availability_zone_not_supported_exception.AvailabilityZoneNotSupportedException: <p>The specified Availability Zone is not supported.</p>
        capo_elastic_load_balancing_v2.errors.duplicate_load_balancer_name_exception.DuplicateLoadBalancerNameException: <p>A load balancer with the specified name already exists.</p>
        capo_elastic_load_balancing_v2.errors.duplicate_tag_keys_exception.DuplicateTagKeysException: <p>A tag key was specified more than once.</p>
        capo_elastic_load_balancing_v2.errors.invalid_configuration_request_exception.InvalidConfigurationRequestException: <p>The requested configuration is not valid.</p>
        capo_elastic_load_balancing_v2.errors.invalid_scheme_exception.InvalidSchemeException: <p>The requested scheme is not valid.</p>
        capo_elastic_load_balancing_v2.errors.invalid_security_group_exception.InvalidSecurityGroupException: <p>The specified security group does not exist.</p>
        capo_elastic_load_balancing_v2.errors.invalid_subnet_exception.InvalidSubnetException: <p>The specified subnet is out of available addresses.</p>
        capo_elastic_load_balancing_v2.errors.operation_not_permitted_exception.OperationNotPermittedException: <p>This operation is not allowed.</p>
        capo_elastic_load_balancing_v2.errors.resource_in_use_exception.ResourceInUseException: <p>A specified resource is in use.</p>
        capo_elastic_load_balancing_v2.errors.subnet_not_found_exception.SubnetNotFoundException: <p>The specified subnet does not exist.</p>
        capo_elastic_load_balancing_v2.errors.too_many_load_balancers_exception.TooManyLoadBalancersException: <p>You've reached the limit on the number of load balancers for your Amazon Web Services account.</p>
        capo_elastic_load_balancing_v2.errors.too_many_tags_exception.TooManyTagsException: <p>You've reached the limit on the number of tags for this resource.</p>
        capo_elastic_load_balancing_v2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To create an Internet-facing load balancer
        This example creates an Internet-facing load balancer and enables the Availability Zones for the specified subnets.

        >>> await client.create_load_balancer(name='my-load-balancer', subnets=['subnet-b7d581c0', 'subnet-8360a9e7'])
        To create an internal load balancer
        This example creates an internal load balancer and enables the Availability Zones for the specified subnets.

        >>> await client.create_load_balancer(name='my-internal-load-balancer', subnets=['subnet-b7d581c0', 'subnet-8360a9e7'], security_groups=[], scheme='internal')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_elastic_load_balancing_v2.types.create_load_balancer_input.CreateLoadBalancerInput]",
    ) -> AsyncOperationResponse[
        "capo_elastic_load_balancing_v2.types.create_load_balancer_output.CreateLoadBalancerOutput"
    ]:
        import capo_elastic_load_balancing_v2._operations.elastic_load_balancing_v10.create_load_balancer

        (
            output,
            http_response,
        ) = await capo_elastic_load_balancing_v2._operations.elastic_load_balancing_v10.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_v2.types.create_load_balancer_input.CreateLoadBalancerInput = {}
    if name is not None:
        input_["name"] = name
    if subnets is not None:
        input_["subnets"] = subnets
    if subnet_mappings is not None:
        input_["subnet_mappings"] = subnet_mappings
    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
    if type is not None:
        input_["type"] = type
    if ip_address_type is not None:
        input_["ip_address_type"] = ip_address_type
    if customer_owned_ipv4_pool is not None:
        input_["customer_owned_ipv4_pool"] = customer_owned_ipv4_pool
    if enable_prefix_for_ipv6_source_nat is not None:
        input_["enable_prefix_for_ipv6_source_nat"] = (
            enable_prefix_for_ipv6_source_nat
        )
    if ipam_pools is not None:
        input_["ipam_pools"] = ipam_pools

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