Updated on 2026-01-05 GMT+08:00

Creating a Proxy Instance

Function

This API is used to create a proxy instance in ELB mode. Before calling this API:

Calling Method

For details, see Calling APIs.

Authorization Information

Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.

  • If you are using role/policy-based authorization, see Permissions and Supported Actions for details on the required permissions.
  • If you are using identity policy-based authorization, the following identity policy-based permissions are required.

    Action

    Access Level

    Resource Type (*: required)

    Condition Key

    Alias

    Dependency

    gaussdbformysql:proxy:create

    Write

    instance *

    • g:EnterpriseProjectId

    • g:ResourceTag/<tag-key>

    • gaussdb:instance:modifyProxy
    • gaussdb:proxy:create

    -

URI

POST /v3/{project_id}/instances/{instance_id}/proxy

Table 1 URI parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Definition

Project ID of a tenant in a region.

To obtain this value, see Obtaining a Project ID.

Constraints

N/A

Range

The value contains 32 characters. Only letters and digits are allowed.

Default Value

N/A

instance_id

Yes

String

Definition

Instance ID, which uniquely identifies an instance.

Constraints

N/A

Range

The value contains 36 characters with a suffix of in07. Only letters and digits are allowed.

Default Value

N/A

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Definition

User token. To obtain this value, call the IAM API for obtaining a user token.

The value of X-Subject-Token in the response header is the token value.

Constraints

N/A

Range

N/A

Default Value

N/A

X-Language

No

String

Definition

Request language type.

Constraints

N/A

Range

  • en-us

  • zh-cn

Default Value

en-us

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

flavor_ref

Yes

String

Definition

Specification code of the proxy instance.

Constraints

N/A

Range

To obtain this value, see the spec_code field returned in Querying Proxy Instance Specifications.

Default Value

N/A

node_num

Yes

Integer

Definition

Number of proxy instance nodes.

Constraints

N/A

Range

2–16

Default Value

N/A

proxy_name

No

String

Definition

Proxy instance name.

Constraints

Instances of the same type can have the same name under the same tenant.

Range

The name must start with a letter and consist of 4 to 64 characters. Only letters (case-sensitive), digits, hyphens (-), and underscores (_) are allowed.

Default Value

N/A

proxy_mode

No

String

Definition

Proxy instance type.

Constraints

N/A

Range

  • readwrite: read/write

  • readonly: read-only

Default Value

readwrite

route_mode

No

Integer

Definition

Routing policy of the proxy instance.

Constraints

N/A

Range

  • 0: weighted

  • 1: load balancing (The primary node does not process read requests.)

  • 2: load balancing (The primary node processes read requests.)

Default Value

0

nodes_read_weight

No

Array of NodesWeight objects

Definition

Read weights of database nodes.

Constraints

If proxy_mode is set to readonly, you can only assign weights for read replicas.

subnet_id

No

String

Definition

Subnet ID. You can obtain the value with either of the following methods:

  • Method 1: Log in to the VPC console and click the target subnet on the Subnets page. You can view the subnet ID on the displayed page.

  • Method 2: Query the subnet ID through the VPC API. For details, see Querying Subnets.

Constraints

N/A

Range

N/A

Default Value

N/A

new_node_auto_add_status

No

String

Definition

Whether new nodes are automatically associated with proxy instances.

Constraints

N/A

Range

  • ON: New nodes are automatically associated with proxy instances.

  • OFF: New nodes are not automatically associated with proxy instances.

Default Value

OFF

new_node_weight

No

Integer

Definition

Read weight of a new node.

Constraints

This parameter is mandatory when new_node_auto_add_status is set to ON.

Range

  • If route_mode is 0 and new_node_auto_add_status is ON, the value of this parameter is between 0 and 1000.

  • If route_mode is not 0 and new_node_auto_add_status is OFF, this parameter is unavailable.

Default Value

N/A

Table 4 NodesWeight

Parameter

Mandatory

Type

Description

id

No

String

Definition

Database node ID.

Constraints

The node ID must belong to the corresponding instance.

Range

The value contains 36 characters, starting with a UUID and ending with no07. Only letters and digits are allowed.

Default Value

N/A

weight

No

Integer

Definition

Node weight.

Constraints

N/A

Range

  • route_mode set to 0: The value range is 0 to 1000.

  • route_mode set to 1: The value for the primary node is 0 and the value for read replicas is 0 or 1.

  • route_mode set to 2: The value for the primary node is 1 and the value for read replicas is 0 or 1.

Response Parameters

Status code: 201

Table 5 Response body parameters

Parameter

Type

Description

job_id

String

Definition

Task ID.

Range

N/A

Status code: 400

Table 6 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 500

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Request

Creating a proxy instance (The proxy instance specifications are 2 vCPUs and 8 GB memory, and the proxy mode is read-only)

POST https://{endpoint}/v3/0483b6b16e954cb88930a360d2c4e663/instances/43e4feaab48f11e89039fa163ebaa7e4br01/proxy
{
  "flavor_ref" : "gaussdb.proxy.large.x86.2",
  "node_num" : 2,
  "proxy_name" : "gaussdb-proxy",
  "proxy_mode" : "readonly",
  "route_mode" : 0,
  "nodes_read_weight" : [ {
    "id" : "45021bf73a244312a3f2af95092feeecno07",
    "weight" : 50
  }, {
    "id" : "d78a65690cea4af5ad14585e110ff89bno07",
    "weight" : 400
  } ],
  "subnet_id" : "6991d82d-9166-4aff-a1fa-d2a8748b7084"
}

Example Response

Status code: 201

Success.

{
  "job_id" : "04efe8e2-9255-44ae-a98b-d87cae411890"
}

SDK Sample Code

The SDK sample code is as follows.

Creating a proxy instance (The proxy instance specifications are 2 vCPUs and 8 GB memory, and the proxy mode is read-only.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.gaussdb.v3.region.GaussDBRegion;
import com.huaweicloud.sdk.gaussdb.v3.*;
import com.huaweicloud.sdk.gaussdb.v3.model.*;

import java.util.List;
import java.util.ArrayList;

public class CreateGaussMySqlProxySolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        GaussDBClient client = GaussDBClient.newBuilder()
                .withCredential(auth)
                .withRegion(GaussDBRegion.valueOf("<YOUR REGION>"))
                .build();
        CreateGaussMySqlProxyRequest request = new CreateGaussMySqlProxyRequest();
        request.withInstanceId("{instance_id}");
        OpenMysqlProxyRequestBody body = new OpenMysqlProxyRequestBody();
        List<NodesWeight> listbodyNodesReadWeight = new ArrayList<>();
        listbodyNodesReadWeight.add(
            new NodesWeight()
                .withId("45021bf73a244312a3f2af95092feeecno07")
                .withWeight(50)
        );
        listbodyNodesReadWeight.add(
            new NodesWeight()
                .withId("d78a65690cea4af5ad14585e110ff89bno07")
                .withWeight(400)
        );
        body.withSubnetId("6991d82d-9166-4aff-a1fa-d2a8748b7084");
        body.withNodesReadWeight(listbodyNodesReadWeight);
        body.withRouteMode(0);
        body.withProxyMode(OpenMysqlProxyRequestBody.ProxyModeEnum.fromValue("readonly"));
        body.withProxyName("gaussdb-proxy");
        body.withNodeNum(2);
        body.withFlavorRef("gaussdb.proxy.large.x86.2");
        request.withBody(body);
        try {
            CreateGaussMySqlProxyResponse response = client.createGaussMySqlProxy(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

Creating a proxy instance (The proxy instance specifications are 2 vCPUs and 8 GB memory, and the proxy mode is read-only.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkgaussdb.v3.region.gaussdb_region import GaussDBRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkgaussdb.v3 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = GaussDBClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(GaussDBRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = CreateGaussMySqlProxyRequest()
        request.instance_id = "{instance_id}"
        listNodesReadWeightbody = [
            NodesWeight(
                id="45021bf73a244312a3f2af95092feeecno07",
                weight=50
            ),
            NodesWeight(
                id="d78a65690cea4af5ad14585e110ff89bno07",
                weight=400
            )
        ]
        request.body = OpenMysqlProxyRequestBody(
            subnet_id="6991d82d-9166-4aff-a1fa-d2a8748b7084",
            nodes_read_weight=listNodesReadWeightbody,
            route_mode=0,
            proxy_mode="readonly",
            proxy_name="gaussdb-proxy",
            node_num=2,
            flavor_ref="gaussdb.proxy.large.x86.2"
        )
        response = client.create_gauss_my_sql_proxy(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Creating a proxy instance (The proxy instance specifications are 2 vCPUs and 8 GB memory, and the proxy mode is read-only.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    gaussdb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := gaussdb.NewGaussDBClient(
        gaussdb.GaussDBClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.CreateGaussMySqlProxyRequest{}
	request.InstanceId = "{instance_id}"
	idNodesReadWeight:= "45021bf73a244312a3f2af95092feeecno07"
	weightNodesReadWeight:= int32(50)
	idNodesReadWeight1:= "d78a65690cea4af5ad14585e110ff89bno07"
	weightNodesReadWeight1:= int32(400)
	var listNodesReadWeightbody = []model.NodesWeight{
        {
            Id: &idNodesReadWeight,
            Weight: &weightNodesReadWeight,
        },
        {
            Id: &idNodesReadWeight1,
            Weight: &weightNodesReadWeight1,
        },
    }
	subnetIdOpenMysqlProxyRequestBody:= "6991d82d-9166-4aff-a1fa-d2a8748b7084"
	routeModeOpenMysqlProxyRequestBody:= int32(0)
	proxyModeOpenMysqlProxyRequestBody:= model.GetOpenMysqlProxyRequestBodyProxyModeEnum().READONLY
	proxyNameOpenMysqlProxyRequestBody:= "gaussdb-proxy"
	request.Body = &model.OpenMysqlProxyRequestBody{
		SubnetId: &subnetIdOpenMysqlProxyRequestBody,
		NodesReadWeight: &listNodesReadWeightbody,
		RouteMode: &routeModeOpenMysqlProxyRequestBody,
		ProxyMode: &proxyModeOpenMysqlProxyRequestBody,
		ProxyName: &proxyNameOpenMysqlProxyRequestBody,
		NodeNum: int32(2),
		FlavorRef: "gaussdb.proxy.large.x86.2",
	}
	response, err := client.CreateGaussMySqlProxy(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Code

For details, see Status Codes.

Error Code

For details, see Error Codes.