Skip to content

create_load_balancer

create_load_balancer(
    load_balancer_name: ResourceName,
    instance_port: Port,
    *,
    config_overrides: Optional[LightsailClientConfig] = None,
    health_check_path: Optional[string] = None,
    certificate_name: Optional[ResourceName] = None,
    certificate_domain_name: Optional[DomainName] = None,
    certificate_alternative_names: Optional[DomainNameList] = None,
    tags: Optional[TagList] = None,
    ip_address_type: Optional[IpAddressType] = None,
    tls_policy_name: Optional[string] = None,
) -> CreateLoadBalancerResult

Creates a Lightsail load balancer. To learn more about deciding whether to load balance your application, see Configure your Lightsail instances for load balancing. You can create up to 10 load balancers per AWS Region in your account.

When you create a load balancer, you can specify a unique name and port settings. To change additional load balancer settings, use the UpdateLoadBalancerAttribute operation.

The create load balancer operation supports tag-based access control via request tags. For more information, see the Amazon Lightsail Developer Guide.

Parameters:

  • load_balancer_name (ResourceName) –

    The name of your load balancer.

  • instance_port (Port) –

    The instance port where you're creating your load balancer.

  • health_check_path (Optional[string], default: None ) –

    The path you provided to perform the load balancer health check. If you didn't specify a health check path, Lightsail uses the root path of your website ("/").

    You may want to specify a custom health check path other than the root of your application if your home page loads slowly or has a lot of media or scripting on it.

  • certificate_name (Optional[ResourceName], default: None ) –

    The name of the SSL/TLS certificate.

    If you specify certificateName, then certificateDomainName is required (and vice-versa).

  • certificate_domain_name (Optional[DomainName], default: None ) –

    The domain name with which your certificate is associated (example.com).

    If you specify certificateDomainName, then certificateName is required (and vice-versa).

  • certificate_alternative_names (Optional[DomainNameList], default: None ) –

    The optional alternative domains and subdomains to use with your SSL/TLS certificate (www.example.com, example.com, m.example.com, blog.example.com).

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

    The tag keys and optional values to add to the resource during create.

    Use the TagResource action to tag a resource after it's created.

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

    The IP address type for the load balancer.

    The possible values are ipv4 for IPv4 only, ipv6 for IPv6 only, and dualstack for IPv4 and IPv6.

    The default value is dualstack.

  • tls_policy_name (Optional[string], default: None ) –

    The name of the TLS policy to apply to the load balancer.

    Use the GetLoadBalancerTlsPolicies action to get a list of TLS policy names that you can specify.

    For more information about load balancer TLS policies, see Configuring TLS security policies on your Amazon Lightsail load balancers in the Amazon Lightsail Developer Guide.

Raises:

  • AccessDeniedException –

    Lightsail throws this exception when the user cannot be authenticated or uses invalid credentials to access a resource.

  • AccountSetupInProgressException –

    Lightsail throws this exception when an account is still in the setup in progress state.

  • InvalidInputException –

    Lightsail throws this exception when user input does not conform to the validation rules of an input field.

    Domain and distribution APIs are only available in the N. Virginia (us-east-1) Amazon Web Services Region. Please set your Amazon Web Services Region configuration to us-east-1 to create, view, or edit these resources.

  • NotFoundException –

    Lightsail throws this exception when it cannot find a resource.

  • OperationFailureException –

    Lightsail throws this exception when an operation fails to execute.

  • RegionSetupInProgressException –

    Lightsail throws this exception when an operation is performed on resources in an opt-in Region that is currently being set up.

  • ServiceException –

    A general service exception.

  • UnauthenticatedException –

    Lightsail throws this exception when the user has not been authenticated.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_lightsail/_services/lightsail.py
def create_load_balancer(
    self,
    load_balancer_name: "capo_lightsail.types.resource_name.ResourceName",
    instance_port: "capo_lightsail.types.port.Port",
    *,
    config_overrides: Optional[LightsailClientConfig] = None,
    health_check_path: Optional["capo_lightsail.types.string.string"] = None,
    certificate_name: Optional[
        "capo_lightsail.types.resource_name.ResourceName"
    ] = None,
    certificate_domain_name: Optional[
        "capo_lightsail.types.domain_name.DomainName"
    ] = None,
    certificate_alternative_names: Optional[
        "capo_lightsail.types.domain_name_list.DomainNameList"
    ] = None,
    tags: Optional["capo_lightsail.types.tag_list.TagList"] = None,
    ip_address_type: Optional[
        "capo_lightsail.types.ip_address_type.IpAddressType"
    ] = None,
    tls_policy_name: Optional["capo_lightsail.types.string.string"] = None,
) -> "capo_lightsail.types.create_load_balancer_result.CreateLoadBalancerResult":
    """<p>Creates a Lightsail load balancer. To learn more about deciding whether to load balance your application, see <a href="https://docs.aws.amazon.com/lightsail/latest/userguide/configure-lightsail-instances-for-load-balancing">Configure your Lightsail instances for load balancing</a>. You can create up to 10 load balancers per AWS Region in your account.</p> <p>When you create a load balancer, you can specify a unique name and port settings. To change additional load balancer settings, use the <code>UpdateLoadBalancerAttribute</code> operation.</p> <p>The <code>create load balancer</code> operation supports tag-based access control via request tags. For more information, see the <a href="https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-controlling-access-using-tags">Amazon Lightsail Developer Guide</a>.</p>

    Args:
        load_balancer_name: <p>The name of your load balancer.</p>
        instance_port: <p>The instance port where you're creating your load balancer.</p>
        health_check_path: <p>The path you provided to perform the load balancer health check. If you didn't specify a health check path, Lightsail uses the root path of your website (<code>"/"</code>).</p> <p>You may want to specify a custom health check path other than the root of your application if your home page loads slowly or has a lot of media or scripting on it.</p>
        certificate_name: <p>The name of the SSL/TLS certificate.</p> <p>If you specify <code>certificateName</code>, then <code>certificateDomainName</code> is required (and vice-versa).</p>
        certificate_domain_name: <p>The domain name with which your certificate is associated (<code>example.com</code>).</p> <p>If you specify <code>certificateDomainName</code>, then <code>certificateName</code> is required (and vice-versa).</p>
        certificate_alternative_names: <p>The optional alternative domains and subdomains to use with your SSL/TLS certificate (<code>www.example.com</code>, <code>example.com</code>, <code>m.example.com</code>, <code>blog.example.com</code>).</p>
        tags: <p>The tag keys and optional values to add to the resource during create.</p> <p>Use the <code>TagResource</code> action to tag a resource after it's created.</p>
        ip_address_type: <p>The IP address type for the load balancer.</p> <p>The possible values are <code>ipv4</code> for IPv4 only, <code>ipv6</code> for IPv6 only, and <code>dualstack</code> for IPv4 and IPv6.</p> <p>The default value is <code>dualstack</code>.</p>
        tls_policy_name: <p>The name of the TLS policy to apply to the load balancer.</p> <p>Use the <a href="https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_GetLoadBalancerTlsPolicies.html">GetLoadBalancerTlsPolicies</a> action to get a list of TLS policy names that you can specify.</p> <p>For more information about load balancer TLS policies, see <a href="https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-configure-load-balancer-tls-security-policy">Configuring TLS security policies on your Amazon Lightsail load balancers</a> in the <i>Amazon Lightsail Developer Guide</i>.</p>

    Raises:
        capo_lightsail.errors.access_denied_exception.AccessDeniedException: <p>Lightsail throws this exception when the user cannot be authenticated or uses invalid credentials to access a resource.</p>
        capo_lightsail.errors.account_setup_in_progress_exception.AccountSetupInProgressException: <p>Lightsail throws this exception when an account is still in the setup in progress state.</p>
        capo_lightsail.errors.invalid_input_exception.InvalidInputException: <p>Lightsail throws this exception when user input does not conform to the validation rules of an input field.</p> <note> <p>Domain and distribution APIs are only available in the N. Virginia (<code>us-east-1</code>) Amazon Web Services Region. Please set your Amazon Web Services Region configuration to <code>us-east-1</code> to create, view, or edit these resources.</p> </note>
        capo_lightsail.errors.not_found_exception.NotFoundException: <p>Lightsail throws this exception when it cannot find a resource.</p>
        capo_lightsail.errors.operation_failure_exception.OperationFailureException: <p>Lightsail throws this exception when an operation fails to execute.</p>
        capo_lightsail.errors.region_setup_in_progress_exception.RegionSetupInProgressException: <p>Lightsail throws this exception when an operation is performed on resources in an opt-in Region that is currently being set up.</p>
        capo_lightsail.errors.service_exception.ServiceException: <p>A general service exception.</p>
        capo_lightsail.errors.unauthenticated_exception.UnauthenticatedException: <p>Lightsail throws this exception when the user has not been authenticated.</p>
        capo_lightsail.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_lightsail.types.create_load_balancer_request.CreateLoadBalancerRequest]",
    ) -> OperationResponse[
        "capo_lightsail.types.create_load_balancer_result.CreateLoadBalancerResult"
    ]:
        import capo_lightsail._operations.lightsail_20161128.create_load_balancer

        output, http_response = (
            capo_lightsail._operations.lightsail_20161128.create_load_balancer.create_load_balancer(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateLoadBalancer")
    )
    input_: capo_lightsail.types.create_load_balancer_request.CreateLoadBalancerRequest = {
        "load_balancer_name": load_balancer_name,
        "instance_port": instance_port,
    }
    if health_check_path is not None:
        input_["health_check_path"] = health_check_path
    if certificate_name is not None:
        input_["certificate_name"] = certificate_name
    if certificate_domain_name is not None:
        input_["certificate_domain_name"] = certificate_domain_name
    if certificate_alternative_names is not None:
        input_["certificate_alternative_names"] = certificate_alternative_names
    if tags is not None:
        input_["tags"] = tags
    if ip_address_type is not None:
        input_["ip_address_type"] = ip_address_type
    if tls_policy_name is not None:
        input_["tls_policy_name"] = tls_policy_name

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output