All Products
Search
Document Center

Server Load Balancer:CreateServerGroup

Last Updated:Jul 18, 2024

Creates a server group in a region.

Operation description

CreateServerGroup is an asynchronous operation. After a request is sent, the system returns a request ID and runs the task in the background. You can call ListServerGroups to query the status of a server group.

  • If a server group is in the Creating state, it indicates that the server group is being created.
  • If a server group is in the Available state, it indicates that the server group is created.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer.

Authorization information

There is currently no authorization information disclosed in the API.

Request parameters

ParameterTypeRequiredDescriptionExample
ServerGroupNamestringYes

The name of the server group. The name must be 2 to 128 characters in length, and can contain letters, digits, periods (.), underscores (_), and hyphens (-). The name must start with a letter.

sg-atstuj3rtoptyui****
ServerGroupTypestringNo

The type of server group. Valid values:

  • Instance (default): allows you to add servers by specifying Ecs, Eni, or Eci.
  • Ip: allows you to add servers by specifying IP addresses.
  • Fc: allows you to add servers by specifying functions of Function Compute.
Instance
VpcIdstringNo

The ID of the virtual private cloud (VPC). You can add only servers that are deployed in the specified VPC to the server group.

Note This parameter takes effect when the ServerGroupType parameter is set to Instance or Ip.
vpc-bp15zckdt37pq72zv****
SchedulerstringNo

The scheduling algorithm. Valid values:

  • Wrr (default): The weighted round-robin algorithm is used. Backend servers that have higher weights receive more requests than those that have lower weights.
  • Wlc: The weighted least connections algorithm is used. Requests are distributed based on the weights and the number of connections to backend servers. If two backend servers have the same weight, the backend server that has fewer connections is expected to receive more requests.
  • Sch: The consistent hashing algorithm is used. Requests from the same source IP address are distributed to the same backend server.
Note This parameter takes effect when the ServerGroupType parameter is set to Instance or Ip.
Wrr
ProtocolstringNo

The backend protocol. Valid values:

  • HTTP (default): The server group can be associated with HTTPS, HTTP, and QUIC listeners.
  • HTTPS: The server group can be associated with HTTPS listeners.
  • gRPC: The server group can be associated with HTTPS and QUIC listeners.
Note If the ServerGroupType parameter is set to Fc, you can set Protocol only to HTTP.
HTTP
ResourceGroupIdstringNo

The ID of the resource group.

rg-atstuj3rtop****
HealthCheckConfigobjectYes

The configuration of health checks.

HealthCheckConnectPortintegerNo

The backend port that is used for health checks.

Valid values: 0 to 65535.

The default value is 0, which specifies that the port of a backend server is used for health checks.

80
HealthCheckEnabledbooleanYes

Specifies whether to enable the health check feature. Valid values:

  • true
  • false
Note If the ServerGroupType parameter is set to Instance or Ip, the health check feature is enabled by default. If the ServerGroupType parameter is set to Fc, the health check feature is disabled by default.
true
HealthCheckHoststringNo

The domain name that is used for health checks. The domain name must meet the following requirements:

  • The domain name must be 1 to 80 characters in length.
  • The domain name can contain lowercase letters, digits, hyphens (-), and periods (.).
  • The domain name can contain at least one period (.) but cannot start or end with a period (.).
  • The rightmost domain label of the domain name can contain only letters, and cannot contain digits or hyphens (-).
  • The domain name cannot start or end with a hyphen (-).
Note This parameter takes effect only if HealthCheckProtocol is set to HTTP or HTTPS.
www.example.com
HealthCheckCodesarrayNo

The HTTP status codes that indicate healthy backend servers.

stringNo

The HTTP status code that indicates healthy backend servers.

  • When HealthCheckProtocol is set to HTTP or HTTPS, you can set HealthCheckCodes to http_2xx (default value), http_3xx, http_4xx, and http_5xx. Separate multiple HTTP status codes with commas (,).
  • If HealthCheckProtocol is set to gRPC, the valid values for HealthCheckCodes are from 0 to 99. The default value is 0. Value ranges are supported. You can specify at most 20 value ranges. Separate multiple value ranges with commas (,).
Note This parameter takes effect only if HealthCheckProtocol is set to HTTP, HTTPS, or gRPC.
http_2xx
HealthCheckHttpVersionstringNo

The version of the HTTP protocol. Valid values: HTTP1.0 and HTTP1.1. Default value: HTTP1.1.

Note This parameter takes effect only if HealthCheckProtocol is set to HTTP or HTTPS.
HTTP1.1
HealthCheckIntervalintegerNo

The interval at which health checks are performed. Unit: seconds.

Valid values: 1 to 50.

Default value: 2.

2
HealthCheckMethodstringNo

The HTTP method that is used for health checks. Valid values:

  • GET: If the length of a response exceeds 8 KB, the response is truncated. However, the health check result is not affected.
  • POST: By default, gRPC health checks use the POST method.
  • HEAD (default): By default, HTTP and HTTPS use the HEAD method.
Note This parameter takes effect only if HealthCheckProtocol is set to HTTP, HTTPS, or gRPC.
HEAD
HealthCheckPathstringNo

The URL that is used for health checks.

The URL must be 1 to 80 characters in length, and can contain letters, digits, and the following special characters: - / . % ? # & =. It can also contain the following extended characters: _ ; ~ ! ( ) * [ ] @ $ ^ : ' , +. The URL must start with a forward slash (/).

Note This parameter takes effect only if HealthCheckProtocol is set to HTTP or HTTPS.
/test/index.html
HealthCheckProtocolstringNo

The protocol that is used for health checks. Valid values:

  • HTTP: HTTP health checks simulate browser behaviors by sending HEAD or GET requests to probe the availability of backend servers.
  • HTTPS: HTTPS health checks simulate browser behaviors by sending HEAD or GET requests to probe the availability of backend servers. HTTPS provides higher security than HTTP because HTTPS supports data encryption.
  • TCP: TCP health checks send TCP SYN packets to a backend server to check whether the port of the backend server is reachable.
  • gRPC: gRPC health checks send POST or GET requests to a backend server to check whether the backend server is healthy.
HTTP
HealthCheckTimeoutintegerNo

The timeout period of a health check response. If a backend server does not respond within the specified timeout period, the backend server is declared unhealthy. Unit: seconds.

Valid values: 1 to 300.

Default value: 5.

Note If the value of HealthCHeckTimeout is smaller than the value of HealthCheckInterval, HealthCHeckTimeout does not take effect. The value of HealthCheckInterval specifies the timeout period.
5
HealthyThresholdintegerNo

The number of times that an unhealthy backend server must consecutively pass health checks before it is declared healthy. In this case, the health status changes from fail to success.

Valid values: 2 to 10.

Default value: 3.

3
UnhealthyThresholdintegerNo

The number of times that a healthy backend server must consecutively fail health checks before it is declared unhealthy. In this case, the health status changes from success to fail.

Valid values: 2 to 10.

Default value: 3.

3
StickySessionConfigobjectNo

The configuration of session persistence.

Note This parameter takes effect when the ServerGroupType parameter is set to Instance or Ip.
CookiestringNo

The cookie that you want to configure for the server.

The cookie must be 1 to 200 characters in length, and can contain only ASCII letters and digits. It cannot contain commas (,), semicolons (;), or space characters. It cannot start with a dollar sign ($).

Note This parameter takes effect only when StickySessionEnabled is set to true and StickySessionType is set to server.
B490B5EBF6F3CD402E515D22BCDA****
CookieTimeoutintegerNo

The maximum amount of time to wait before the session cookie expires. Unit: seconds.

Valid values: 1 to 86400.

Default value: 1000.

Note This parameter takes effect only when StickySessionEnabled is set to true and StickySessionType is set to Insert.
1000
StickySessionEnabledbooleanNo

Specifies whether to enable session persistence. Valid values:

  • true
  • false
Note This parameter takes effect when the ServerGroupType parameter is set to Instance or Ip.
false
StickySessionTypestringNo

The method that is used to handle cookies. Valid values:

  • Insert (default value): inserts a cookie. The first time a client accesses SLB, SLB inserts the SERVERID cookie into the HTTP or HTTPS response packet. Subsequent requests from the client that carry this cookie are forwarded to the same backend server as the first request.
  • Server: rewrites a cookie. SLB rewrites the custom cookies in requests from a client. Subsequent requests from the client that carry the new cookie are forwarded to the same backend server as the first request.
Note This parameter takes effect when the StickySessionEnabled parameter is set to true.
Insert
ClientTokenstringNo

The client token that is used to ensure the idempotence of the request.

You can use the client to generate the token, but you must make sure that the token is unique among different requests. The token can contain only ASCII characters.

Note If you do not specify this parameter, the system automatically uses the request ID as the client token. The request ID may be different for each request.
5A2CFF0E-5718-45B5-9D4D-70B3FF3898
DryRunbooleanNo

Specifies whether to perform only a dry run, without performing the actual request. Valid values:

  • true: performs only a dry run. The system checks the request for potential issues, including missing parameter values, incorrect request syntax, and service limits. If the request fails the dry run, an error code is returned. If the request passes the dry run, the DryRunOperation error code is returned.
  • false (default): performs a dry run and performs the actual request. If the request passes the dry run, a 2xx HTTP status code is returned and the operation is performed.
false
UpstreamKeepaliveEnabledbooleanNo

Specifies whether to enable persistent TCP connections.

false
ServiceNamestringNo

This parameter is available only if the ALB Ingress controller is used. In this case, set this parameter to the name of the Kubernetes Service that is associated with the server group.

test
UchConfigobjectNo

The configuration of consistent hashing based on URLs.

TypestringYes

The type of the parameter.

QueryString
ValuestringYes

The parameter value for consistent hashing.

abc
Tagarray<object>No

The tag.

objectNo
KeystringNo

The tag key. The tag key can be up to 128 characters in length, and cannot start with acs: or aliyun. It cannot contain http:// or https://.

env
ValuestringNo

The tag value. The tag value can be up to 128 characters in length, and cannot start with acs: or aliyun. It cannot contain http:// or https://.

product

Response parameters

ParameterTypeDescriptionExample
object

The response parameters.

JobIdstring

The ID of the asynchronous job.

72dcd26b-f12d-4c27-b3af-18f6aed5****
RequestIdstring

The request ID.

365F4154-92F6-4AE4-92F8-7FF34B540710
ServerGroupIdstring

The ID of the server group.

sg-atstuj3rtoptyui****

Examples

Sample success responses

JSONformat

{
  "JobId": "72dcd26b-f12d-4c27-b3af-18f6aed5****",
  "RequestId": "365F4154-92F6-4AE4-92F8-7FF34B540710",
  "ServerGroupId": "sg-atstuj3rtoptyui****"
}

Error codes

HTTP status codeError codeError messageDescription
400QuotaExceeded.ServerGroupsNumThe quota of %s is exceeded, usage %s/%s.The quota of %s is exceeded, usage %s/%s.
400Mismatch.LoadBalancerEditionAndSlowStartEnableThe %s and %s are mismatched.The %s and %s are mismatched.
400Mismatch.ServerGroupSchedulerAndSlowStartEnableThe %s and %s are mismatched.The %s and %s are mismatched.
400QuotaExceeded.SlowStartDurationThe quota of %s is exceeded, usage %s/%s.The quota of %s is exceeded, usage %s/%s.
400UnsupportedFeature.SlowStartThe feature of %s is not supported.-
400Mismatch.LoadBalancerEditionAndConnectionDrainThe %s and %s are mismatched.The %s and %s are mismatched.
400QuotaExceeded.ConnectionDrainTimeoutThe quota of %s is exceeded, usage %s/%s.The quota of %s is exceeded, usage %s/%s.
400UnsupportedFeature.ConnectionDrainThe feature of %s is not supported.The feature of %s is not supported.
400NotExist.ResourceGroupResourceGroup does not exist.-
400OperationDenied.VpcNotSupportIpv6The operation is not allowed because of VpcNotSupportIpv6.This operation is not allowed because the IPv6 function is not enabled for the current VPC.
400UnsupportedFeature.FcServerGroupServer groups of type FC are not supported.Server groups of type FC are not supported
404ResourceNotFound.VpcThe specified resource %s is not found.The specified resource %s is not found.

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2024-02-27The Error code has changedView Change Details
2024-02-23The Error code has changed. The request parameters of the API has changedView Change Details
2023-11-03The Error code has changed. The request parameters of the API has changedView Change Details
2023-04-11The Error code has changed. The request parameters of the API has changedView Change Details