createLoadBalancer method

Future<CreateLoadBalancerResult> createLoadBalancer({
  1. required int instancePort,
  2. required String loadBalancerName,
  3. List<String>? certificateAlternativeNames,
  4. String? certificateDomainName,
  5. String? certificateName,
  6. String? healthCheckPath,
  7. IpAddressType? ipAddressType,
  8. List<Tag>? tags,
  9. String? tlsPolicyName,
})

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.

May throw AccessDeniedException. May throw AccountSetupInProgressException. May throw InvalidInputException. May throw NotFoundException. May throw OperationFailureException. May throw RegionSetupInProgressException. May throw ServiceException. May throw UnauthenticatedException.

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

Parameter loadBalancerName : The name of your load balancer.

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

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

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

Parameter certificateName : The name of the SSL/TLS certificate.

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

Parameter healthCheckPath : 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.

Parameter ipAddressType : 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.

Parameter tags : 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.

Parameter tlsPolicyName : 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.

Implementation

Future<CreateLoadBalancerResult> createLoadBalancer({
  required int instancePort,
  required String loadBalancerName,
  List<String>? certificateAlternativeNames,
  String? certificateDomainName,
  String? certificateName,
  String? healthCheckPath,
  IpAddressType? ipAddressType,
  List<Tag>? tags,
  String? tlsPolicyName,
}) async {
  _s.validateNumRange(
    'instancePort',
    instancePort,
    -1,
    65535,
    isRequired: true,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'Lightsail_20161128.CreateLoadBalancer'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'instancePort': instancePort,
      'loadBalancerName': loadBalancerName,
      if (certificateAlternativeNames != null)
        'certificateAlternativeNames': certificateAlternativeNames,
      if (certificateDomainName != null)
        'certificateDomainName': certificateDomainName,
      if (certificateName != null) 'certificateName': certificateName,
      if (healthCheckPath != null) 'healthCheckPath': healthCheckPath,
      if (ipAddressType != null) 'ipAddressType': ipAddressType.value,
      if (tags != null) 'tags': tags,
      if (tlsPolicyName != null) 'tlsPolicyName': tlsPolicyName,
    },
  );

  return CreateLoadBalancerResult.fromJson(jsonResponse.body);
}