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. List<Tag>? tags,
})

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 5 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 Lightsail Dev Guide.

May throw ServiceException. May throw InvalidInputException. May throw NotFoundException. May throw OperationFailureException. May throw AccessDeniedException. May throw AccountSetupInProgressException. 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 (e.g., www.example.com, example.com, m.example.com, blog.example.com).

Parameter certificateDomainName : The domain name with which your certificate is associated (e.g., 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 (e.g., "/").

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 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.

Implementation

Future<CreateLoadBalancerResult> createLoadBalancer({
  required int instancePort,
  required String loadBalancerName,
  List<String>? certificateAlternativeNames,
  String? certificateDomainName,
  String? certificateName,
  String? healthCheckPath,
  List<Tag>? tags,
}) async {
  ArgumentError.checkNotNull(instancePort, 'instancePort');
  _s.validateNumRange(
    'instancePort',
    instancePort,
    -1,
    65535,
    isRequired: true,
  );
  ArgumentError.checkNotNull(loadBalancerName, 'loadBalancerName');
  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 (tags != null) 'tags': tags,
    },
  );

  return CreateLoadBalancerResult.fromJson(jsonResponse.body);
}