Creating an Instance
Function
This API is used to create an instance in the pay-per-use or yearly/monthly mode.
Calling Method
For details, see Calling APIs.
URI
POST /v2/{engine}/{project_id}/instances
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
engine |
Yes |
String |
Message engine. |
project_id |
Yes |
String |
Project ID. For details, see Obtaining a Project ID. |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
Yes |
String |
Instance name. An instance name can contain 4 to 64 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed. |
description |
No |
String |
Description of an instance. The description supports up to 1024 characters.
NOTE:
The backslash () and quotation mark (") are special characters for JSON messages. When using these characters in a parameter value, add the escape character () before the characters, for example, \ and ". |
engine |
Yes |
String |
Message engine. Value: rabbitmq. |
engine_version |
Yes |
String |
Version of the message engine.
|
storage_space |
Yes |
Integer |
Message storage space in GB. Value range:
|
access_user |
No |
String |
A username must start with a letter and only letters, digits, hyphens (-), and underscores (_) are allowed. It can contain 4 to 64 characters. |
password |
No |
String |
Instance password. The password must meet the following complexity requirements:
|
vpc_id |
Yes |
String |
VPC ID. To obtain it, log in to the VPC console and view the VPC ID on the VPC details page. |
security_group_id |
Yes |
String |
Security group ID. To obtain it, log in to the VPC console and view the security group ID on the security group details page. |
subnet_id |
Yes |
String |
Subnet ID. To obtain it, log in to VPC console and click the target subnet on the Subnets page. You can view the network ID on the displayed page. |
available_zones |
Yes |
Array of strings |
ID of the AZ where instance brokers reside and which has available resources. Obtain the AZ ID by referring to Listing AZ Information. This parameter cannot be empty or null. |
product_id |
Yes |
String |
Product ID. Obtain a product ID from Querying Product Specifications List. If the product is of the cluster type (that is, type is set to cluster), the broker_num field is mandatory. |
broker_num |
No |
Integer |
Number of brokers. If the product is of the single-node type, there can be only 1 broker. If the product is of the cluster type, there can be 3, 5, or 7 brokers. If the product type is single:
If the product type is cluster:
|
maintain_begin |
No |
String |
Indicates the time at which a maintenance time window starts. Format: HH:mm.
|
maintain_end |
No |
String |
Indicates the time at which a maintenance time window ends. Format: HH:mm.
|
enable_publicip |
No |
Boolean |
Whether to enable public access for the RabbitMQ instance.
|
publicip_id |
No |
String |
ID of the EIP bound to the RabbitMQ instance. This parameter is mandatory if public access is enabled (that is, enable_publicip is set to true). |
ssl_enable |
No |
Boolean |
Whether to enable SSL encryption for access.
|
storage_spec_code |
Yes |
String |
Storage I/O specification. For details, see Disk Types and Disk Performance. Value range:
|
enterprise_project_id |
No |
String |
Enterprise project ID. This parameter is mandatory for an enterprise project account. |
tags |
No |
Array of TagEntity objects |
Tag list. |
bss_param |
No |
BssParam object |
Parameter related to the yearly/monthly billing mode. If this parameter is left blank, the billing mode is pay-per-use by default. If this parameter is not left blank, the billing mode is yearly/monthly. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
key |
No |
String |
Tag key.
|
value |
No |
String |
Tag value.
|
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
is_auto_renew |
No |
Boolean |
Whether auto renewal is enabled. Options:
By default, auto renewal is disabled. |
charging_mode |
No |
String |
Billing mode. This parameter specifies a payment mode. Options:
The default value is postPaid. |
is_auto_pay |
No |
Boolean |
Specifies whether the order is automatically or manually paid. Options:
The default payment mode is manual. |
period_type |
No |
String |
Subscription period type. Options:
**This parameter is valid and mandatory only when chargingMode is set to prePaid. ** |
period_num |
No |
Integer |
Subscribed periods. Options:
**This parameter is valid and mandatory only when chargingMode is set to prePaid. ** |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
instance_id |
String |
Instance ID. |
Example Requests
-
Creating a pay-per-use RabbitMQ instance whose version is 3.8.35, specifications are 2 vCPUs | 4 GB x 1, and storage space is 100 GB
POST https://{endpoint}/v2/{engine}/{project_id}/instances { "name" : "rabbitmq-demo", "description" : "", "engine" : "RabbitMQ", "engine_version" : "3.8.35", "storage_space" : 100, "access_user" : "******", "password" : "******", "vpc_id" : "1e93f86e-13af-46c8-97d6-d40fa62b76c2", "security_group_id" : "0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8", "subnet_id" : "b5fa806c-35e7-4299-b659-b39398dd4718", "available_zones" : [ "d573142f24894ef3bd3664de068b44b0" ], "product_id" : "c6.2u4g.single", "ssl_enable" : false, "enable_publicip" : false, "publicip_id" : "", "storage_spec_code" : "dms.physical.storage.high.v2" }
-
Creating a yearly/monthly RabbitMQ instance whose version is 3.8.35, specifications are 2 vCPUs | 4 GB x 1, and storage space is 100 GB
POST https://{endpoint}/v2/{engine}/{project_id}/instances { "name" : "rabbitmq-demo", "description" : "", "engine" : "RabbitMQ", "engine_version" : "3.8.35", "storage_space" : 100, "access_user" : "******", "password" : "******", "vpc_id" : "1e93f86e-13af-46c8-97d6-d40fa62b76c2", "security_group_id" : "0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8", "subnet_id" : "b5fa806c-35e7-4299-b659-b39398dd4718", "available_zones" : [ "d573142f24894ef3bd3664de068b44b0" ], "product_id" : "c6.2u4g.single", "ssl_enable" : false, "enable_publicip" : false, "publicip_id" : "", "storage_spec_code" : "dms.physical.storage.high.v2", "bss_param" : { "charging_mode" : "prePaid", "period_type" : "month", "period_num" : 1, "is_auto_pay" : true } }
-
Creating a RabbitMQ instance with AMQP-0-9-1, amqp.b1.large.1, and 100 GB
POST https://{endpoint}/v2/{engine}/{project_id}/instances { "name" : "rabbitmq-aor-demo", "description" : "", "engine" : "RabbitMQ", "engine_version" : "AMQP-0-9-1", "storage_space" : 100, "vpc_id" : "05590544-f553-4158-be38-c791589ad303", "security_group_id" : "030f635d-b407-4ffb-b530-6b4eaf8edc03", "subnet_id" : "89c1cb26-787b-4d66-a6e4-1bd887f19183", "available_zones" : [ "9f1c5806706d4c1fb0eb72f0a9b18c77" ], "product_id" : "amqp.b1.large.1", "broker_num" : 1, "ssl_enable" : false, "enable_publicip" : false, "storage_spec_code" : "dms.physical.storage.high.v2", "enable_acl" : true, "enterprise_project_id" : 0 }
Example Responses
Status code: 200
Instance created successfully.
{ "instance_id" : "8959ab1c-7n1a-yyb1-a05t-93dfc361b32d" }
SDK Sample Code
The SDK sample code is as follows.
-
Creating a pay-per-use RabbitMQ instance whose version is 3.8.35, specifications are 2 vCPUs | 4 GB x 1, and storage space is 100 GB
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.rabbitmq.v2.region.RabbitMQRegion; import com.huaweicloud.sdk.rabbitmq.v2.*; import com.huaweicloud.sdk.rabbitmq.v2.model.*; import java.util.List; import java.util.ArrayList; public class CreatePostPaidInstanceByEngineSolution { 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); RabbitMQClient client = RabbitMQClient.newBuilder() .withCredential(auth) .withRegion(RabbitMQRegion.valueOf("<YOUR REGION>")) .build(); CreatePostPaidInstanceByEngineRequest request = new CreatePostPaidInstanceByEngineRequest(); request.withEngine(CreatePostPaidInstanceByEngineRequest.EngineEnum.fromValue("{engine}")); CreateInstanceReq body = new CreateInstanceReq(); List<String> listbodyAvailableZones = new ArrayList<>(); listbodyAvailableZones.add("d573142f24894ef3bd3664de068b44b0"); body.withStorageSpecCode(CreateInstanceReq.StorageSpecCodeEnum.fromValue("dms.physical.storage.high.v2")); body.withSslEnable(false); body.withPublicipId(""); body.withEnablePublicip(false); body.withProductId("c6.2u4g.single"); body.withAvailableZones(listbodyAvailableZones); body.withSubnetId("b5fa806c-35e7-4299-b659-b39398dd4718"); body.withSecurityGroupId("0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8"); body.withVpcId("1e93f86e-13af-46c8-97d6-d40fa62b76c2"); body.withPassword("******"); body.withAccessUser("******"); body.withStorageSpace(100); body.withEngineVersion("3.8.35"); body.withEngine(CreateInstanceReq.EngineEnum.fromValue("RabbitMQ")); body.withDescription(""); body.withName("rabbitmq-demo"); request.withBody(body); try { CreatePostPaidInstanceByEngineResponse response = client.createPostPaidInstanceByEngine(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 yearly/monthly RabbitMQ instance whose version is 3.8.35, specifications are 2 vCPUs | 4 GB x 1, and storage space is 100 GB
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 71 72 73 74 75 76
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.rabbitmq.v2.region.RabbitMQRegion; import com.huaweicloud.sdk.rabbitmq.v2.*; import com.huaweicloud.sdk.rabbitmq.v2.model.*; import java.util.List; import java.util.ArrayList; public class CreatePostPaidInstanceByEngineSolution { 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); RabbitMQClient client = RabbitMQClient.newBuilder() .withCredential(auth) .withRegion(RabbitMQRegion.valueOf("<YOUR REGION>")) .build(); CreatePostPaidInstanceByEngineRequest request = new CreatePostPaidInstanceByEngineRequest(); request.withEngine(CreatePostPaidInstanceByEngineRequest.EngineEnum.fromValue("{engine}")); CreateInstanceReq body = new CreateInstanceReq(); BssParam bssParambody = new BssParam(); bssParambody.withChargingMode(BssParam.ChargingModeEnum.fromValue("prePaid")) .withIsAutoPay(true) .withPeriodType(BssParam.PeriodTypeEnum.fromValue("month")) .withPeriodNum(1); List<String> listbodyAvailableZones = new ArrayList<>(); listbodyAvailableZones.add("d573142f24894ef3bd3664de068b44b0"); body.withBssParam(bssParambody); body.withStorageSpecCode(CreateInstanceReq.StorageSpecCodeEnum.fromValue("dms.physical.storage.high.v2")); body.withSslEnable(false); body.withPublicipId(""); body.withEnablePublicip(false); body.withProductId("c6.2u4g.single"); body.withAvailableZones(listbodyAvailableZones); body.withSubnetId("b5fa806c-35e7-4299-b659-b39398dd4718"); body.withSecurityGroupId("0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8"); body.withVpcId("1e93f86e-13af-46c8-97d6-d40fa62b76c2"); body.withPassword("******"); body.withAccessUser("******"); body.withStorageSpace(100); body.withEngineVersion("3.8.35"); body.withEngine(CreateInstanceReq.EngineEnum.fromValue("RabbitMQ")); body.withDescription(""); body.withName("rabbitmq-demo"); request.withBody(body); try { CreatePostPaidInstanceByEngineResponse response = client.createPostPaidInstanceByEngine(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 RabbitMQ instance with AMQP-0-9-1, amqp.b1.large.1, and 100 GB
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
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.rabbitmq.v2.region.RabbitMQRegion; import com.huaweicloud.sdk.rabbitmq.v2.*; import com.huaweicloud.sdk.rabbitmq.v2.model.*; import java.util.List; import java.util.ArrayList; public class CreatePostPaidInstanceByEngineSolution { 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); RabbitMQClient client = RabbitMQClient.newBuilder() .withCredential(auth) .withRegion(RabbitMQRegion.valueOf("<YOUR REGION>")) .build(); CreatePostPaidInstanceByEngineRequest request = new CreatePostPaidInstanceByEngineRequest(); request.withEngine(CreatePostPaidInstanceByEngineRequest.EngineEnum.fromValue("{engine}")); CreateInstanceReq body = new CreateInstanceReq(); List<String> listbodyAvailableZones = new ArrayList<>(); listbodyAvailableZones.add("9f1c5806706d4c1fb0eb72f0a9b18c77"); body.withEnterpriseProjectId("0"); body.withStorageSpecCode(CreateInstanceReq.StorageSpecCodeEnum.fromValue("dms.physical.storage.high.v2")); body.withSslEnable(false); body.withEnablePublicip(false); body.withBrokerNum(CreateInstanceReq.BrokerNumEnum.NUMBER_1); body.withProductId("amqp.b1.large.1"); body.withAvailableZones(listbodyAvailableZones); body.withSubnetId("89c1cb26-787b-4d66-a6e4-1bd887f19183"); body.withSecurityGroupId("030f635d-b407-4ffb-b530-6b4eaf8edc03"); body.withVpcId("05590544-f553-4158-be38-c791589ad303"); body.withStorageSpace(100); body.withEngineVersion("AMQP-0-9-1"); body.withEngine(CreateInstanceReq.EngineEnum.fromValue("RabbitMQ")); body.withDescription(""); body.withName("rabbitmq-aor-demo"); request.withBody(body); try { CreatePostPaidInstanceByEngineResponse response = client.createPostPaidInstanceByEngine(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 pay-per-use RabbitMQ instance whose version is 3.8.35, specifications are 2 vCPUs | 4 GB x 1, and storage space is 100 GB
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
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkrabbitmq.v2.region.rabbitmq_region import RabbitMQRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkrabbitmq.v2 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 = RabbitMQClient.new_builder() \ .with_credentials(credentials) \ .with_region(RabbitMQRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreatePostPaidInstanceByEngineRequest() request.engine = "{engine}" listAvailableZonesbody = [ "d573142f24894ef3bd3664de068b44b0" ] request.body = CreateInstanceReq( storage_spec_code="dms.physical.storage.high.v2", ssl_enable=False, publicip_id="", enable_publicip=False, product_id="c6.2u4g.single", available_zones=listAvailableZonesbody, subnet_id="b5fa806c-35e7-4299-b659-b39398dd4718", security_group_id="0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8", vpc_id="1e93f86e-13af-46c8-97d6-d40fa62b76c2", password="******", access_user="******", storage_space=100, engine_version="3.8.35", engine="RabbitMQ", description="", name="rabbitmq-demo" ) response = client.create_post_paid_instance_by_engine(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 yearly/monthly RabbitMQ instance whose version is 3.8.35, specifications are 2 vCPUs | 4 GB x 1, and storage space is 100 GB
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
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkrabbitmq.v2.region.rabbitmq_region import RabbitMQRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkrabbitmq.v2 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 = RabbitMQClient.new_builder() \ .with_credentials(credentials) \ .with_region(RabbitMQRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreatePostPaidInstanceByEngineRequest() request.engine = "{engine}" bssParambody = BssParam( charging_mode="prePaid", is_auto_pay=True, period_type="month", period_num=1 ) listAvailableZonesbody = [ "d573142f24894ef3bd3664de068b44b0" ] request.body = CreateInstanceReq( bss_param=bssParambody, storage_spec_code="dms.physical.storage.high.v2", ssl_enable=False, publicip_id="", enable_publicip=False, product_id="c6.2u4g.single", available_zones=listAvailableZonesbody, subnet_id="b5fa806c-35e7-4299-b659-b39398dd4718", security_group_id="0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8", vpc_id="1e93f86e-13af-46c8-97d6-d40fa62b76c2", password="******", access_user="******", storage_space=100, engine_version="3.8.35", engine="RabbitMQ", description="", name="rabbitmq-demo" ) response = client.create_post_paid_instance_by_engine(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 RabbitMQ instance with AMQP-0-9-1, amqp.b1.large.1, and 100 GB
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
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkrabbitmq.v2.region.rabbitmq_region import RabbitMQRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkrabbitmq.v2 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 = RabbitMQClient.new_builder() \ .with_credentials(credentials) \ .with_region(RabbitMQRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreatePostPaidInstanceByEngineRequest() request.engine = "{engine}" listAvailableZonesbody = [ "9f1c5806706d4c1fb0eb72f0a9b18c77" ] request.body = CreateInstanceReq( enterprise_project_id="0", storage_spec_code="dms.physical.storage.high.v2", ssl_enable=False, enable_publicip=False, broker_num=1, product_id="amqp.b1.large.1", available_zones=listAvailableZonesbody, subnet_id="89c1cb26-787b-4d66-a6e4-1bd887f19183", security_group_id="030f635d-b407-4ffb-b530-6b4eaf8edc03", vpc_id="05590544-f553-4158-be38-c791589ad303", storage_space=100, engine_version="AMQP-0-9-1", engine="RabbitMQ", description="", name="rabbitmq-aor-demo" ) response = client.create_post_paid_instance_by_engine(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 pay-per-use RabbitMQ instance whose version is 3.8.35, specifications are 2 vCPUs | 4 GB x 1, and storage space is 100 GB
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" rabbitmq "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rabbitmq/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rabbitmq/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rabbitmq/v2/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 := rabbitmq.NewRabbitMQClient( rabbitmq.RabbitMQClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreatePostPaidInstanceByEngineRequest{} request.Engine = model.GetCreatePostPaidInstanceByEngineRequestEngineEnum().ENGINE var listAvailableZonesbody = []string{ "d573142f24894ef3bd3664de068b44b0", } sslEnableCreateInstanceReq:= false publicipIdCreateInstanceReq:= "" enablePublicipCreateInstanceReq:= false passwordCreateInstanceReq:= "******" accessUserCreateInstanceReq:= "******" descriptionCreateInstanceReq:= "" request.Body = &model.CreateInstanceReq{ StorageSpecCode: model.GetCreateInstanceReqStorageSpecCodeEnum().DMS_PHYSICAL_STORAGE_HIGH, SslEnable: &sslEnableCreateInstanceReq, PublicipId: &publicipIdCreateInstanceReq, EnablePublicip: &enablePublicipCreateInstanceReq, ProductId: "c6.2u4g.single", AvailableZones: listAvailableZonesbody, SubnetId: "b5fa806c-35e7-4299-b659-b39398dd4718", SecurityGroupId: "0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8", VpcId: "1e93f86e-13af-46c8-97d6-d40fa62b76c2", Password: &passwordCreateInstanceReq, AccessUser: &accessUserCreateInstanceReq, StorageSpace: int32(100), EngineVersion: "3.8.35", Engine: model.GetCreateInstanceReqEngineEnum().RABBIT_MQ, Description: &descriptionCreateInstanceReq, Name: "rabbitmq-demo", } response, err := client.CreatePostPaidInstanceByEngine(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
Creating a yearly/monthly RabbitMQ instance whose version is 3.8.35, specifications are 2 vCPUs | 4 GB x 1, and storage space is 100 GB
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 71 72 73 74 75 76
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" rabbitmq "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rabbitmq/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rabbitmq/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rabbitmq/v2/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 := rabbitmq.NewRabbitMQClient( rabbitmq.RabbitMQClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreatePostPaidInstanceByEngineRequest{} request.Engine = model.GetCreatePostPaidInstanceByEngineRequestEngineEnum().ENGINE chargingModeBssParam:= model.GetBssParamChargingModeEnum().PRE_PAID isAutoPayBssParam:= true periodTypeBssParam:= model.GetBssParamPeriodTypeEnum().MONTH periodNumBssParam:= int32(1) bssParambody := &model.BssParam{ ChargingMode: &chargingModeBssParam, IsAutoPay: &isAutoPayBssParam, PeriodType: &periodTypeBssParam, PeriodNum: &periodNumBssParam, } var listAvailableZonesbody = []string{ "d573142f24894ef3bd3664de068b44b0", } sslEnableCreateInstanceReq:= false publicipIdCreateInstanceReq:= "" enablePublicipCreateInstanceReq:= false passwordCreateInstanceReq:= "******" accessUserCreateInstanceReq:= "******" descriptionCreateInstanceReq:= "" request.Body = &model.CreateInstanceReq{ BssParam: bssParambody, StorageSpecCode: model.GetCreateInstanceReqStorageSpecCodeEnum().DMS_PHYSICAL_STORAGE_HIGH, SslEnable: &sslEnableCreateInstanceReq, PublicipId: &publicipIdCreateInstanceReq, EnablePublicip: &enablePublicipCreateInstanceReq, ProductId: "c6.2u4g.single", AvailableZones: listAvailableZonesbody, SubnetId: "b5fa806c-35e7-4299-b659-b39398dd4718", SecurityGroupId: "0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8", VpcId: "1e93f86e-13af-46c8-97d6-d40fa62b76c2", Password: &passwordCreateInstanceReq, AccessUser: &accessUserCreateInstanceReq, StorageSpace: int32(100), EngineVersion: "3.8.35", Engine: model.GetCreateInstanceReqEngineEnum().RABBIT_MQ, Description: &descriptionCreateInstanceReq, Name: "rabbitmq-demo", } response, err := client.CreatePostPaidInstanceByEngine(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
Creating a RabbitMQ instance with AMQP-0-9-1, amqp.b1.large.1, and 100 GB
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
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" rabbitmq "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rabbitmq/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rabbitmq/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rabbitmq/v2/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 := rabbitmq.NewRabbitMQClient( rabbitmq.RabbitMQClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreatePostPaidInstanceByEngineRequest{} request.Engine = model.GetCreatePostPaidInstanceByEngineRequestEngineEnum().ENGINE var listAvailableZonesbody = []string{ "9f1c5806706d4c1fb0eb72f0a9b18c77", } enterpriseProjectIdCreateInstanceReq:= "0" sslEnableCreateInstanceReq:= false enablePublicipCreateInstanceReq:= false brokerNumCreateInstanceReq:= model.GetCreateInstanceReqBrokerNumEnum().E_1 descriptionCreateInstanceReq:= "" request.Body = &model.CreateInstanceReq{ EnterpriseProjectId: &enterpriseProjectIdCreateInstanceReq, StorageSpecCode: model.GetCreateInstanceReqStorageSpecCodeEnum().DMS_PHYSICAL_STORAGE_HIGH, SslEnable: &sslEnableCreateInstanceReq, EnablePublicip: &enablePublicipCreateInstanceReq, BrokerNum: &brokerNumCreateInstanceReq, ProductId: "amqp.b1.large.1", AvailableZones: listAvailableZonesbody, SubnetId: "89c1cb26-787b-4d66-a6e4-1bd887f19183", SecurityGroupId: "030f635d-b407-4ffb-b530-6b4eaf8edc03", VpcId: "05590544-f553-4158-be38-c791589ad303", StorageSpace: int32(100), EngineVersion: "AMQP-0-9-1", Engine: model.GetCreateInstanceReqEngineEnum().RABBIT_MQ, Description: &descriptionCreateInstanceReq, Name: "rabbitmq-aor-demo", } response, err := client.CreatePostPaidInstanceByEngine(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 Codes
Status Code |
Description |
---|---|
200 |
Instance created successfully. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot