CreateServerGroup

Updated at:

Creates a server group in a specified region.

Operation description

The CreateServerGroup operation is asynchronous. The system returns a request ID, but the server group of the Network Load Balancer (NLB) is not yet created, and the creation task is still running in the background. You can call the GetJobStatus operation to query the creation status of the server group:

  • If the task status is Succeeded, the server group is created.

  • If the task status is Processing, the server group is being created. In this state, you can only perform query operations and cannot perform other operations.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

nlb:CreateServerGroup

create

*ServerGroup

acs:nlb:{#regionId}:{#accountId}:servergroup/*

*VPC

acs:vpc:{#regionId}:{#accountId}:vpc/{#VpcId}

None None

Request parameters

Parameter

Type

Required

Description

Example

ServerGroupType

string

No

The server group type. Valid values:

  • Instance (default): server type. This type of server group supports adding Ecs, Eni, and Eci instances.

  • Ip: IP address type. This type of server group supports directly adding backend servers by IP address.

Instance

ServerGroupName

string

Yes

The name of the server group.

The name must be 2 to 128 characters in length, and must start with a letter or Chinese character. It can contain digits, periods (.), underscores (_), and hyphens (-).

NLB_ServerGroup

AddressIPVersion

string

No

The protocol version. Valid values:

  • ipv4 (default): IPv4.

  • DualStack: dual-stack.

ipv4

IpVersionAffinityMode

string

No

The traffic scheduling policy in dual-stack mode. Valid values:

  • NonAffinity (default): non-affinity mode. Traffic is forwarded to healthy backend servers based on the scheduling algorithm regardless of the IP protocol version of the source.

  • Affinity: affinity mode. Traffic is forwarded based on the IP protocol version of the request source. IPv4 requests are forwarded only to IPv4 backend servers, and IPv6 requests are forwarded only to IPv6 backend servers.

Note

This parameter takes effect only when AddressIPVersion is set to DualStack.

Affinity

Protocol

string

No

The communication protocol used to forward traffic to backend servers. Valid values:

  • TCP (default)

  • UDP

  • TCP_UDP

Note
  • If this parameter is set to UDP, the server group can be associated only with UDP listeners.

  • If this parameter is set to TCP and PreserveClientIpEnabled is set to true, the server group can be associated only with TCP listeners.

  • If this parameter is set to TCP and PreserveClientIpEnabled is set to false, the server group can be associated with TCPSSL and TCP listeners.

  • If this parameter is set to TCP_UDP, the server group can be associated with TCP and UDP listeners.

TCP

VpcId

string

Yes

The ID of the VPC where the server group is deployed.

Note

If ServerGroupType is set to Instance, only servers in this VPC can be added to the server group.

vpc-bp15zckdt37pq72zv****

AnyPortEnabled

boolean

No

Specifies whether to enable all-port forwarding. Valid values:

  • true: enables all-port forwarding.

  • false (default): disables all-port forwarding.

false

ConnectionDrainEnabled

boolean

No

Specifies whether to enable connection draining. Valid values:

  • true: enables connection draining.

  • false (default): disables connection draining.

false

ConnectionDrainTimeout

integer

No

The timeout period for connection draining. Unit: seconds. Valid values: 0 to 900.

10

Scheduler

string

No

The scheduling algorithm. Valid values:

  • Wrr (default): weighted round-robin. Backend servers with higher weights are more likely to be polled.

  • Wlc: weighted least connections. In addition to the weight of each backend server, the actual load (number of connections) of the backend server is also considered. If the weights are the same, backend servers with fewer current connections are more likely to be polled.

  • rr: round-robin. External requests are distributed to backend servers in sequence.

  • sch: source IP hash. Requests from the same source IP address are scheduled to the same backend server.

  • tch: 4-tuple hash. Consistent hashing based on the 4-tuple (source IP address, destination IP address, source port, and destination port). Requests from the same flow are scheduled to the same backend server.

  • qch: QUIC ID hash. Requests with the same QUIC ID are scheduled to the same backend server.

Note

QUIC ID hash is supported only when the backend protocol is UDP.

Wrr

PreserveClientIpEnabled

boolean

No

Specifies whether to enable client IP address preservation. Valid values:

  • true (default): enables client IP address preservation.

  • false: disables client IP address preservation.

Note

If Protocol is set to TCP and this parameter is set to true, the server group cannot be associated with TCPSSL listeners.

true

HealthCheckConfig

object

No

The health check configuration.

HealthCheckConnectPort

integer

No

The port of the backend server used for health checks.

Valid values: 0 to 65535.

Default value: 0. This value indicates that the port of the backend server is used for health checks.

0

HealthCheckConnectTimeout

integer

No

The maximum timeout period for a health check response. Unit: seconds. Valid values: 1 to 300. Default value: 5.

5

HealthCheckDomain

string

No

The domain name used for health checks. Valid values:

  • $SERVER_IP: the internal IP address of the backend server.

  • domain: a specified domain name. The domain name must be 1 to 80 characters in length, and can contain only letters, digits, hyphens (-), and periods (.).

Note

This parameter takes effect only when HealthCheckType is set to HTTP.

$SERVER_IP

HealthCheckEnabled

boolean

No

Specifies whether to enable health checks. Valid values:

  • true (default): enables health checks.

  • false: disables health checks.

true

HealthCheckExp

string

No

The query string in the request for UDP listener health checks. The string can contain only letters and digits, and can be up to 512 characters in length.

ok

HealthCheckHttpCode

array

No

The HTTP status codes for healthy responses. Separate multiple status codes with commas (,). Valid values: http_2xx (default), http_3xx, http_4xx, and http_5xx.

Note

This parameter takes effect only when HealthCheckType is set to HTTP.

string

No

The HTTP status codes for healthy responses. Separate multiple status codes with commas (,). Valid values: http_2xx (default), http_3xx, http_4xx, and http_5xx.

Note

This parameter takes effect only when HealthCheckType is set to HTTP.

http_2xx

HealthCheckHttpVersion

string

No

The HTTP protocol version for health checks. Valid values: HTTP1.0 (default) and HTTP1.1.

Note

This parameter takes effect only when HealthCheckType is set to HTTP.

HTTP1.0

HealthCheckInterval

integer

No

The interval between two consecutive health checks. Unit: seconds. Default value: 5.

  • If HealthCheckType is set to TCP or HTTP, valid values are 1 to 50.

  • If HealthCheckType is set to UDP, valid values are 1 to 300. You must set the interval to be greater than or equal to the response timeout period to ensure that UDP probe responses are not misjudged as unresponsive due to a timeout.

5

HealthCheckReq

string

No

The query string in the request for UDP listener health checks. The string can contain only letters and digits, and can be up to 512 characters in length.

hello

HealthCheckType

string

No

The protocol used for health checks. Valid values:

  • TCP

  • HTTP

  • UDP

TCP

HealthCheckUrl

string

No

The health check path.

The path must be 1 to 80 characters in length, and can contain only letters, digits, and the following special characters: -/.%?#&. It must start with a forward slash (/).

Note

This parameter takes effect only when HealthCheckType is set to HTTP.

/test/index.html

HealthyThreshold

integer

No

The number of consecutive successful health checks that must occur before the health check status of a backend server is changed from fail to success.

Valid values: 2 to 10.

Default value: 2.

2

HttpCheckMethod

string

No

The HTTP method used for health checks. Valid values: GET (default) and HEAD.

Note

This parameter takes effect only when HealthCheckType is set to HTTP.

GET

UnhealthyThreshold

integer

No

The number of consecutive failed health checks that must occur before the health check status of a backend server is changed from success to fail.

Valid values: 2 to 10.

Default value: 2.

2

ResourceGroupId

string

No

The ID of the resource group to which the server group belongs.

rg-atstuj3rtop****

DryRun

boolean

No

Specifies whether to only precheck the request. Valid values:

  • true: prechecks the request without creating the server group. The system checks whether required parameters are specified, the request format, and service limits. If the request fails the precheck, the corresponding error is returned. If the request passes the precheck, the DryRunOperation error code is returned.

  • false (default): sends the request. If the request passes the precheck, an HTTP 2xx status code is returned and the operation is performed.

true

ClientToken

string

No

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

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

Note

If you do not specify this parameter, the system automatically uses the RequestId of the API request as the ClientToken. The RequestId of each API request is unique.

123e4567-e89b-12d3-a456-426655440000

RegionId

string

No

The region ID of the Network Load Balancer (NLB) instance.

You can call the DescribeRegions operation to query the most recent region list.

cn-hangzhou

Tag

array<object>

No

The list of tags.

object

No

The tag.

Key

string

No

The tag key. The tag key can be up to 64 characters in length, and cannot start with aliyun or acs:. It cannot contain http:// or https://. It can contain letters, digits, underscores (_), periods (.), colons (:), forward slashes (/), equal signs (=), plus signs (+), hyphens (-), and at signs (@).

You can add up to 20 tags in a single call.

env

Value

string

No

The tag value. The tag value can be up to 128 characters in length, and cannot start with aliyun or acs:. It cannot contain http:// or https://. It can contain letters, digits, underscores (_), periods (.), colons (:), forward slashes (/), equal signs (=), plus signs (+), hyphens (-), and at signs (@).

You can add up to 20 tags in a single call.

product

Response elements

Element

Type

Description

Example

object

The server group.

JobId

string

The ID of the asynchronous task.

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

RequestId

string

The request ID.

54B48E3D-DF70-471B-AA93-08E683A1B45

ServerGroupId

string

The ID of the server group.

sgp-atstuj3rtoptyui****

Examples

Success response

JSON format

{
  "JobId": "72dcd26b-f12d-4c27-b3af-18f6aed5****",
  "RequestId": "54B48E3D-DF70-471B-AA93-08E683A1B45",
  "ServerGroupId": "sgp-atstuj3rtoptyui****"
}

Error codes

HTTP status code

Error code

Error message

Description

400 IllegalParam.AnyPortServerGroupConflictWithHealthCheckConfig The param of AnyPortServerGroupConflictWithHealthCheckConfig is illegal. The server group configuration conflicts with the health check settings. Check the configuration parameters.
400 IllegalParamFormat.ParseCreateRsPoolRequestFailed The param format of CreateRsPoolRequest is illegal. The param format of CreateRsPoolRequest is illegal.
400 IllegalParam.PreserveClientIpSwitch The param of PreserveClientIpSwitch is illegal.
400 OperationDenied.VpcNotSupportIpv6 The operation is not allowed because of VpcNotSupportIpv6. The VPC you are using does not support Ipv6.
400 IllegalParam.healthCheckDomain The parameter of healthCheckConfig.healthCheckDomain is illegal. The healthCheckDomain in the health check configuration is invalid. Check the input parameters.
400 OperationDenied.UidNotAllowQuic29 The operation is not allowed because of uid not allow quic29 version.
400 IlleagalParam.healthCheckUrl The parameter of healthCheckUrl in healthCheckConfig is illegal. The URL of the health check used in the health check setting is invalid.
400 IllegalParam.ServerGroupName The param of ServerGroupName is illegal. The ServerGroupName parameter is invalid.
400 DryRunOperation Request validation has been passed with DryRun flag set. Request validation has been passed with DryRun flag set.
400 MissingParam.%s The parameter of %s is missing. The parameter %s is missing. Check the input parameters.
400 IllegalParam.ConnectionDrainTimeout The param of ConnectionDrainTimeout is illegal. The parameter ConnectionDrainTimeout is invalid. Check the input parameters.
400 IllegalParam The param of %s is illegal. The input parameters contain invalid values. Check the input.
400 SystemBusy System is busy, please try again later. The system is busy. Try again later.
400 QuotaExceeded.QuotaInsufficient The quota of %s is exceeded, usage %s/%s. The quota is insufficient, currently used %s/%s. Please modify the quota size in the quota center.
403 Forbidden.NoPermission Authentication is failed for NoPermission. Authentication is failed for NoPermission.
404 ResourceNotFound.Vpc The specified resource of Vpc is not found. The specified VPC resource was not found. Please check the input parameters.
404 ResourceNotFound.ResourceGroup The param of resourceGroup not existed. The resource group does not exist.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.