Creating a Kafka Instance
Function
This API is used to create an instance.
Pay-per-use and yearly/monthly billing modes are available.
Calling Method
For details, see Calling APIs.
URI
POST /v2/{project_id}/kafka/instances
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Definition: Project ID. For details, see Obtaining a Project ID. Constraints: N/A Range: N/A Default Value: N/A |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
Yes |
String |
Definition: Instance name. Constraints: A username must start with a letter. It can contain 4 to 64 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed. Range: N/A Default Value: N/A |
description |
No |
String |
Definition: Description of an instance. Constraints: 0–1,024 characters 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 \". Range: N/A Default Value: N/A |
engine |
Yes |
String |
Definition: Message engine. Constraints: N/A Range: kafka Default Value: N/A |
engine_version |
Yes |
String |
Definition: Message engine version. Constraints: N/A Range:
Default Value: N/A |
broker_num |
Yes |
Integer |
Definition: Number of brokers. Constraints: N/A Range:
Default Value: N/A |
storage_space |
Yes |
Integer |
Definition: Message storage space, in GB. Constraints: N/A Range:
Default Value: N/A |
access_user |
No |
String |
Definition: Authentication username. Constraints: Starts with a letter, consists of 4 to 64 characters, and contains only letters, digits, hyphens (-), and underscores (_). This parameter is mandatory when ssl_enable is set to true. This parameter is invalid when ssl_enable is set to false. Range: N/A Default Value: N/A |
password |
No |
String |
Definition: Instance password. Constraints:
Range: N/A Default Value: N/A |
vpc_id |
Yes |
String |
Definition: VPC ID. You can call the API for querying VPCs to obtain the VPC ID. The VPC ID is in the response body. For details, see Virtual Private Cloud API Reference. Constraints: N/A Range: N/A Default Value: N/A |
security_group_id |
Yes |
String |
Definition: Security group to which the instance belongs. You can call the API for querying security groups to obtain the security group ID. The security group ID is in the response body. For details, see Virtual Private Cloud API Reference. Constraints: N/A Range: N/A Default Value: N/A |
subnet_id |
Yes |
String |
Definition: Subnet information. You can call the API for querying subnets to obtain the subnet ID. The subnet ID is in the response body. For details, see Virtual Private Cloud API Reference. Constraints: N/A Range: N/A Default Value: N/A |
available_zones |
Yes |
Array of strings |
Definition: ID of the AZ where instance brokers reside and which has available resources. Obtain the AZ ID by referring to Listing AZ Information. Constraints: This parameter cannot be empty or null. A Kafka instance should be deployed in 1 AZ or at least 3 AZs. If the instance is deployed in multiple AZs, separate the AZ IDs with commas (,). |
product_id |
Yes |
String |
Definition: Product ID. Obtain the product ID from Querying Product Specifications List. Constraints: N/A Range: N/A Default Value: N/A |
maintain_begin |
No |
String |
Definition: Start time of the maintenance time window. Constraints: The value is in HH:mm format. Range: N/A Default Value: N/A |
maintain_end |
No |
String |
Definition: End time of the maintenance time window. Constraints: The value is in HH:mm format. Range: N/A Default Value: N/A |
enable_publicip |
No |
Boolean |
Definition: Whether to enable public access. Constraints: N/A Range:
Default Value: false |
tenant_ips |
No |
Array of strings |
Definition: You can manually specify IPv4 private IP addresses when creating an instance. Constraints: The number of specified private IP addresses must be equal to or less than the number of created brokers. If the number of specified private IP addresses is less than the number of created brokers, the system automatically assigns private IP addresses to the remaining brokers. |
publicip_id |
No |
String |
Definition: ID of the EIP bound to the instance. Constraints: Use commas (,) to separate multiple EIP IDs. This parameter is mandatory if public access is enabled (that is, enable_publicip is set to true). Range: N/A Default Value: N/A |
ssl_enable |
No |
Boolean |
Definition: Whether SASL is enabled. Constraints: N/A Range:
Default Value: N/A |
kafka_security_protocol |
No |
String |
Definition: Security protocol to use after SASL is enabled. Constraints: If this parameter is left blank, SASL_SSL authentication is enabled by default. This parameter cannot be manually modified once the instance is created. If the port_protocol parameter were used in instance creation, its value is used for the private and public network access security protocols and this parameter becomes invalid. Range:
Default Value: N/A |
sasl_enabled_mechanisms |
No |
Array of strings |
Definition: Authentication mechanism used after SASL is enabled. Constraints: This parameter is mandatory if SASL authentication is enabled (that is, ssl_enable is set to true). If this parameter is left blank, PLAIN authentication is enabled by default. |
port_protocol |
No |
PortProtocol object |
Definition: Kafka instance access mode. PLAINTEXT indicates plaintext access. SASL_SSL or SASL_PLAINTEXT indicates ciphertext access. Constraints: Once enabled, this parameter cannot be disabled. Enable plaintext or ciphertext access, or both. The security protocol for cross-VPC access is the same as that for intranet access. If both ciphertext access and plaintext access are enabled for intranet access, the security protocol for ciphertext access is preferentially used for cross-VPC access. |
retention_policy |
No |
String |
Definition: Action to be taken when the memory usage reaches the disk capacity threshold. Constraints: N/A Range:
Default Value: N/A |
ipv6_enable |
No |
Boolean |
Definition: Whether IPv6 is enabled. Constraints: This parameter is available only when the VPC supports IPv6. Range:
Default Value: false |
disk_encrypted_enable |
No |
Boolean |
Definition: Whether disk encryption is enabled. Constraints: N/A Range:
Default Value: false |
disk_encrypted_key |
No |
String |
Definition: Disk encryption key. If disk encryption is not enabled, this parameter is left blank. Constraints: N/A Range: N/A Default Value: N/A |
connector_enable |
No |
Boolean |
Definition: Whether to enable Smart Connect. Smart Connect synchronizes data between Kafka and other cloud services or between two Kafka instances for backup or migration. Constraints: N/A Range:
Default Value: false |
enable_auto_topic |
No |
Boolean |
Definition: Whether to enable automatic Kafka topic creation. Enabling this function automatically creates a topic when a message is produced in or consumed from a topic that does not exist. Constraints: N/A Range:
Default Value: false |
storage_spec_code |
Yes |
String |
Definition: EVS type. For details about how to select a disk type, see "Disk Types and Disk Performance" in the EVS Service Overview. Constraints: N/A Range:
Default Value: N/A |
enterprise_project_id |
No |
String |
Definition: Enterprise project ID. Constraints: This parameter is mandatory for an enterprise project account. Range: N/A Default Value: N/A |
tags |
No |
Array of TagEntity objects |
Definition: Tags of a Kafka instance. Constraints: N/A |
arch_type |
No |
String |
Definition: CPU architecture. Constraints: N/A Range:
Default Value: N/A |
vpc_client_plain |
No |
Boolean |
Definition: Private plaintext access in a VPC. Constraints: N/A Range: N/A Default Value: N/A |
bss_param |
No |
BssParam object |
Definition: Parameter related to the yearly/monthly billing mode. Constraints: N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
private_plain_enable |
No |
Boolean |
Definition: Whether to enable the private plaintext access mode. Constraints: N/A Range:
Default Value: false |
private_sasl_ssl_enable |
No |
Boolean |
Definition: Whether to enable the private ciphertext access mode using the security protocol SASL_SSL. Constraints: private_sasl_ssl_enable and private_sasl_plaintext_enable cannot be set to true at the same time. Range:
Default Value: false |
private_sasl_plaintext_enable |
No |
Boolean |
Definition: Whether to enable the private ciphertext access mode using the security protocol SASL_PLAINTEXT. Constraints: private_sasl_plaintext_enable and private_sasl_ssl_enable cannot be set to true at the same time. Range:
Default Value: false |
public_plain_enable |
No |
Boolean |
Definition: Whether to enable the public plaintext access mode. Constraints: Enable public access before enabling public plaintext access. Range:
Default Value: false |
public_sasl_ssl_enable |
No |
Boolean |
Definition: Whether to enable the public ciphertext access using the security protocol SASL_SSL. Constraints: public_sasl_ssl_enable and public_sasl_plaintext_enable cannot be set to true at the same time. If this parameter is set to true, public access needs to be enabled for the instance. Range:
Default Value: false |
public_sasl_plaintext_enable |
No |
Boolean |
Definition: Whether to enable the public ciphertext access mode using the security protocol SASL_PLAINTEXT. Constraints: public_sasl_plaintext_enable and public_sasl_ssl_enable cannot be set to true at the same time. If this parameter is set to true, public access needs to be enabled for the instance. Range:
Default Value: false |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
key |
No |
String |
Definition: Tag key. Constraints:
Range: N/A Default Value: N/A |
value |
No |
String |
Definition: Tag value. Constraints:
Range: N/A Default Value: N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
is_auto_renew |
No |
Boolean |
Definition: Indicates whether auto-renewal is enabled. Constraints: N/A Range:
Default Value: false |
charging_mode |
No |
String |
Definition: Billing mode. Constraints: N/A Range:
Default Value: postPaid |
is_auto_pay |
No |
Boolean |
Definition: Whether the order is automatically or manually paid. Constraints: N/A Range:
Default Value: false |
period_type |
No |
String |
Definition: Subscription period type. Constraints: This parameter is valid and mandatory only when chargingMode is set to prePaid. Range:
Default Value: N/A |
period_num |
No |
Integer |
Definition: Number of subscription periods. Constraints: This parameter is valid and mandatory only when chargingMode is set to prePaid. Range:
Default Value: N/A |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
instance_id |
String |
Definition: Instance ID. Range: N/A |
Example Requests
-
Creating a pay-per-use Kafka instance whose version is 2.7, specifications are 2 vCPUs | 4 GB x 3, and storage space is 300 GB
POST https://{endpoint}/v2/{engine}/{project_id}/instances { "name" : "kafka-test", "description" : "", "engine" : "kafka", "engine_version" : "2.7", "storage_space" : 300, "vpc_id" : "********-9b4a-44c5-a964-************", "subnet_id" : "********-8fbf-4438-ba71-************", "security_group_id" : "********-e073-4aad-991f-************", "available_zones" : [ "********706d4c1fb0eb72f0********" ], "product_id" : "c6.2u4g.cluster", "ssl_enable" : true, "kafka_security_protocol" : "SASL_SSL", "sasl_enabled_mechanisms" : [ "SCRAM-SHA-512" ], "storage_spec_code" : "dms.physical.storage.ultra.v2", "broker_num" : 3, "arch_type" : "X86", "enterprise_project_id" : "0", "access_user" : "********", "password" : "********", "enable_publicip" : true, "tags" : [ { "key" : "aaa", "value" : "111" } ], "retention_policy" : "time_base", "disk_encrypted_enable" : true, "disk_encrypted_key" : "********-b953-4875-a743-************", "publicip_id" : "********-88fc-4a8c-86d0-************,********-16af-455d-8d54-************,********-3d69-4367-95ab-************", "vpc_client_plain" : true, "enable_auto_topic" : true, "tenant_ips" : [ "127.xx.xx.x", "127.xx.xx.x", "127.xx.xx.x" ] }
-
Creating a yearly/monthly Kafka instance whose version is 2.7, specifications are 2 vCPUs | 4 GB x 3, and storage space is 300 GB
POST https://{endpoint}/v2/{engine}/{project_id}/instances { "name" : "kafka-test1", "description" : "", "engine" : "kafka", "engine_version" : "2.7", "storage_space" : 300, "vpc_id" : "********-9b4a-44c5-a964-************", "subnet_id" : "********-8fbf-4438-ba71-************", "security_group_id" : "********-e073-4aad-991f-************", "available_zones" : [ "********706d4c1fb0eb72f0********" ], "product_id" : "c6.2u4g.cluster", "ssl_enable" : true, "kafka_security_protocol" : "SASL_SSL", "sasl_enabled_mechanisms" : [ "SCRAM-SHA-512" ], "storage_spec_code" : "dms.physical.storage.ultra.v2", "broker_num" : 3, "arch_type" : "X86", "enterprise_project_id" : "0", "access_user" : "********", "password" : "********", "enable_publicip" : true, "tags" : [ { "key" : "aaa", "value" : "111" } ], "retention_policy" : "time_base", "publicip_id" : "********-88fc-4a8c-86d0-************,********-16af-455d-8d54-************,********-3d69-4367-95ab-************", "vpc_client_plain" : true, "enable_auto_topic" : true, "bss_param" : { "charging_mode" : "prePaid", "period_type" : "month", "period_num" : 1, "is_auto_pay" : true }, "tenant_ips" : [ "127.xx.xx.x", "127.xx.xx.x", "127.xx.xx.x" ] }
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 Kafka instance whose version is 2.7, specifications are 2 vCPUs | 4 GB x 3, and storage space is 300 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
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.kafka.v2.region.KafkaRegion; import com.huaweicloud.sdk.kafka.v2.*; import com.huaweicloud.sdk.kafka.v2.model.*; import java.util.List; import java.util.ArrayList; public class CreatePostPaidKafkaInstanceSolution { 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); KafkaClient client = KafkaClient.newBuilder() .withCredential(auth) .withRegion(KafkaRegion.valueOf("<YOUR REGION>")) .build(); CreatePostPaidKafkaInstanceRequest request = new CreatePostPaidKafkaInstanceRequest(); CreateInstanceByEngineReq body = new CreateInstanceByEngineReq(); List<TagEntity> listbodyTags = new ArrayList<>(); listbodyTags.add( new TagEntity() .withKey("aaa") .withValue("111") ); List<CreateInstanceByEngineReq.SaslEnabledMechanismsEnum> listbodySaslEnabledMechanisms = new ArrayList<>(); listbodySaslEnabledMechanisms.add(CreateInstanceByEngineReq.SaslEnabledMechanismsEnum.fromValue("SCRAM-SHA-512")); List<String> listbodyTenantIps = new ArrayList<>(); listbodyTenantIps.add("127.xx.xx.x"); listbodyTenantIps.add("127.xx.xx.x"); listbodyTenantIps.add("127.xx.xx.x"); List<String> listbodyAvailableZones = new ArrayList<>(); listbodyAvailableZones.add("********706d4c1fb0eb72f0********"); body.withVpcClientPlain(true); body.withArchType("X86"); body.withTags(listbodyTags); body.withEnterpriseProjectId("0"); body.withStorageSpecCode(CreateInstanceByEngineReq.StorageSpecCodeEnum.fromValue("dms.physical.storage.ultra.v2")); body.withEnableAutoTopic(true); body.withDiskEncryptedKey("********-b953-4875-a743-************"); body.withDiskEncryptedEnable(true); body.withRetentionPolicy(CreateInstanceByEngineReq.RetentionPolicyEnum.fromValue("time_base")); body.withSaslEnabledMechanisms(listbodySaslEnabledMechanisms); body.withKafkaSecurityProtocol("SASL_SSL"); body.withSslEnable(true); body.withPublicipId("********-88fc-4a8c-86d0-************,********-16af-455d-8d54-************,********-3d69-4367-95ab-************"); body.withTenantIps(listbodyTenantIps); body.withEnablePublicip(true); body.withProductId("c6.2u4g.cluster"); body.withAvailableZones(listbodyAvailableZones); body.withSubnetId("********-8fbf-4438-ba71-************"); body.withSecurityGroupId("********-e073-4aad-991f-************"); body.withVpcId("********-9b4a-44c5-a964-************"); body.withPassword("********"); body.withAccessUser("********"); body.withStorageSpace(300); body.withBrokerNum(3); body.withEngineVersion("2.7"); body.withEngine(CreateInstanceByEngineReq.EngineEnum.fromValue("kafka")); body.withDescription(""); body.withName("kafka-test"); request.withBody(body); try { CreatePostPaidKafkaInstanceResponse response = client.createPostPaidKafkaInstance(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 Kafka instance whose version is 2.7, specifications are 2 vCPUs | 4 GB x 3, and storage space is 300 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
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.kafka.v2.region.KafkaRegion; import com.huaweicloud.sdk.kafka.v2.*; import com.huaweicloud.sdk.kafka.v2.model.*; import java.util.List; import java.util.ArrayList; public class CreatePostPaidKafkaInstanceSolution { 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); KafkaClient client = KafkaClient.newBuilder() .withCredential(auth) .withRegion(KafkaRegion.valueOf("<YOUR REGION>")) .build(); CreatePostPaidKafkaInstanceRequest request = new CreatePostPaidKafkaInstanceRequest(); CreateInstanceByEngineReq body = new CreateInstanceByEngineReq(); BssParam bssParambody = new BssParam(); bssParambody.withChargingMode(BssParam.ChargingModeEnum.fromValue("prePaid")) .withIsAutoPay(true) .withPeriodType(BssParam.PeriodTypeEnum.fromValue("month")) .withPeriodNum(1); List<TagEntity> listbodyTags = new ArrayList<>(); listbodyTags.add( new TagEntity() .withKey("aaa") .withValue("111") ); List<CreateInstanceByEngineReq.SaslEnabledMechanismsEnum> listbodySaslEnabledMechanisms = new ArrayList<>(); listbodySaslEnabledMechanisms.add(CreateInstanceByEngineReq.SaslEnabledMechanismsEnum.fromValue("SCRAM-SHA-512")); List<String> listbodyTenantIps = new ArrayList<>(); listbodyTenantIps.add("127.xx.xx.x"); listbodyTenantIps.add("127.xx.xx.x"); listbodyTenantIps.add("127.xx.xx.x"); List<String> listbodyAvailableZones = new ArrayList<>(); listbodyAvailableZones.add("********706d4c1fb0eb72f0********"); body.withBssParam(bssParambody); body.withVpcClientPlain(true); body.withArchType("X86"); body.withTags(listbodyTags); body.withEnterpriseProjectId("0"); body.withStorageSpecCode(CreateInstanceByEngineReq.StorageSpecCodeEnum.fromValue("dms.physical.storage.ultra.v2")); body.withEnableAutoTopic(true); body.withRetentionPolicy(CreateInstanceByEngineReq.RetentionPolicyEnum.fromValue("time_base")); body.withSaslEnabledMechanisms(listbodySaslEnabledMechanisms); body.withKafkaSecurityProtocol("SASL_SSL"); body.withSslEnable(true); body.withPublicipId("********-88fc-4a8c-86d0-************,********-16af-455d-8d54-************,********-3d69-4367-95ab-************"); body.withTenantIps(listbodyTenantIps); body.withEnablePublicip(true); body.withProductId("c6.2u4g.cluster"); body.withAvailableZones(listbodyAvailableZones); body.withSubnetId("********-8fbf-4438-ba71-************"); body.withSecurityGroupId("********-e073-4aad-991f-************"); body.withVpcId("********-9b4a-44c5-a964-************"); body.withPassword("********"); body.withAccessUser("********"); body.withStorageSpace(300); body.withBrokerNum(3); body.withEngineVersion("2.7"); body.withEngine(CreateInstanceByEngineReq.EngineEnum.fromValue("kafka")); body.withDescription(""); body.withName("kafka-test1"); request.withBody(body); try { CreatePostPaidKafkaInstanceResponse response = client.createPostPaidKafkaInstance(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 Kafka instance whose version is 2.7, specifications are 2 vCPUs | 4 GB x 3, and storage space is 300 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 77 78
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkkafka.v2.region.kafka_region import KafkaRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkkafka.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 = KafkaClient.new_builder() \ .with_credentials(credentials) \ .with_region(KafkaRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreatePostPaidKafkaInstanceRequest() listTagsbody = [ TagEntity( key="aaa", value="111" ) ] listSaslEnabledMechanismsbody = [ "SCRAM-SHA-512" ] listTenantIpsbody = [ "127.xx.xx.x", "127.xx.xx.x", "127.xx.xx.x" ] listAvailableZonesbody = [ "********706d4c1fb0eb72f0********" ] request.body = CreateInstanceByEngineReq( vpc_client_plain=True, arch_type="X86", tags=listTagsbody, enterprise_project_id="0", storage_spec_code="dms.physical.storage.ultra.v2", enable_auto_topic=True, disk_encrypted_key="********-b953-4875-a743-************", disk_encrypted_enable=True, retention_policy="time_base", sasl_enabled_mechanisms=listSaslEnabledMechanismsbody, kafka_security_protocol="SASL_SSL", ssl_enable=True, publicip_id="********-88fc-4a8c-86d0-************,********-16af-455d-8d54-************,********-3d69-4367-95ab-************", tenant_ips=listTenantIpsbody, enable_publicip=True, product_id="c6.2u4g.cluster", available_zones=listAvailableZonesbody, subnet_id="********-8fbf-4438-ba71-************", security_group_id="********-e073-4aad-991f-************", vpc_id="********-9b4a-44c5-a964-************", password="********", access_user="********", storage_space=300, broker_num=3, engine_version="2.7", engine="kafka", description="", name="kafka-test" ) response = client.create_post_paid_kafka_instance(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 Kafka instance whose version is 2.7, specifications are 2 vCPUs | 4 GB x 3, and storage space is 300 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 77 78 79 80 81 82 83
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkkafka.v2.region.kafka_region import KafkaRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkkafka.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 = KafkaClient.new_builder() \ .with_credentials(credentials) \ .with_region(KafkaRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreatePostPaidKafkaInstanceRequest() bssParambody = BssParam( charging_mode="prePaid", is_auto_pay=True, period_type="month", period_num=1 ) listTagsbody = [ TagEntity( key="aaa", value="111" ) ] listSaslEnabledMechanismsbody = [ "SCRAM-SHA-512" ] listTenantIpsbody = [ "127.xx.xx.x", "127.xx.xx.x", "127.xx.xx.x" ] listAvailableZonesbody = [ "********706d4c1fb0eb72f0********" ] request.body = CreateInstanceByEngineReq( bss_param=bssParambody, vpc_client_plain=True, arch_type="X86", tags=listTagsbody, enterprise_project_id="0", storage_spec_code="dms.physical.storage.ultra.v2", enable_auto_topic=True, retention_policy="time_base", sasl_enabled_mechanisms=listSaslEnabledMechanismsbody, kafka_security_protocol="SASL_SSL", ssl_enable=True, publicip_id="********-88fc-4a8c-86d0-************,********-16af-455d-8d54-************,********-3d69-4367-95ab-************", tenant_ips=listTenantIpsbody, enable_publicip=True, product_id="c6.2u4g.cluster", available_zones=listAvailableZonesbody, subnet_id="********-8fbf-4438-ba71-************", security_group_id="********-e073-4aad-991f-************", vpc_id="********-9b4a-44c5-a964-************", password="********", access_user="********", storage_space=300, broker_num=3, engine_version="2.7", engine="kafka", description="", name="kafka-test1" ) response = client.create_post_paid_kafka_instance(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 Kafka instance whose version is 2.7, specifications are 2 vCPUs | 4 GB x 3, and storage space is 300 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" kafka "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/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 := kafka.NewKafkaClient( kafka.KafkaClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreatePostPaidKafkaInstanceRequest{} keyTags:= "aaa" valueTags:= "111" var listTagsbody = []model.TagEntity{ { Key: &keyTags, Value: &valueTags, }, } var listSaslEnabledMechanismsbody = []model.CreateInstanceByEngineReqSaslEnabledMechanisms{ model.GetCreateInstanceByEngineReqSaslEnabledMechanismsEnum().SCRAM_SHA_512, } var listTenantIpsbody = []string{ "127.xx.xx.x", "127.xx.xx.x", "127.xx.xx.x", } var listAvailableZonesbody = []string{ "********706d4c1fb0eb72f0********", } vpcClientPlainCreateInstanceByEngineReq:= true archTypeCreateInstanceByEngineReq:= "X86" enterpriseProjectIdCreateInstanceByEngineReq:= "0" enableAutoTopicCreateInstanceByEngineReq:= true diskEncryptedKeyCreateInstanceByEngineReq:= "********-b953-4875-a743-************" diskEncryptedEnableCreateInstanceByEngineReq:= true retentionPolicyCreateInstanceByEngineReq:= model.GetCreateInstanceByEngineReqRetentionPolicyEnum().TIME_BASE kafkaSecurityProtocolCreateInstanceByEngineReq:= "SASL_SSL" sslEnableCreateInstanceByEngineReq:= true publicipIdCreateInstanceByEngineReq:= "********-88fc-4a8c-86d0-************,********-16af-455d-8d54-************,********-3d69-4367-95ab-************" enablePublicipCreateInstanceByEngineReq:= true passwordCreateInstanceByEngineReq:= "********" accessUserCreateInstanceByEngineReq:= "********" descriptionCreateInstanceByEngineReq:= "" request.Body = &model.CreateInstanceByEngineReq{ VpcClientPlain: &vpcClientPlainCreateInstanceByEngineReq, ArchType: &archTypeCreateInstanceByEngineReq, Tags: &listTagsbody, EnterpriseProjectId: &enterpriseProjectIdCreateInstanceByEngineReq, StorageSpecCode: model.GetCreateInstanceByEngineReqStorageSpecCodeEnum().DMS_PHYSICAL_STORAGE_ULTRA, EnableAutoTopic: &enableAutoTopicCreateInstanceByEngineReq, DiskEncryptedKey: &diskEncryptedKeyCreateInstanceByEngineReq, DiskEncryptedEnable: &diskEncryptedEnableCreateInstanceByEngineReq, RetentionPolicy: &retentionPolicyCreateInstanceByEngineReq, SaslEnabledMechanisms: &listSaslEnabledMechanismsbody, KafkaSecurityProtocol: &kafkaSecurityProtocolCreateInstanceByEngineReq, SslEnable: &sslEnableCreateInstanceByEngineReq, PublicipId: &publicipIdCreateInstanceByEngineReq, TenantIps: &listTenantIpsbody, EnablePublicip: &enablePublicipCreateInstanceByEngineReq, ProductId: "c6.2u4g.cluster", AvailableZones: listAvailableZonesbody, SubnetId: "********-8fbf-4438-ba71-************", SecurityGroupId: "********-e073-4aad-991f-************", VpcId: "********-9b4a-44c5-a964-************", Password: &passwordCreateInstanceByEngineReq, AccessUser: &accessUserCreateInstanceByEngineReq, StorageSpace: int32(300), BrokerNum: int32(3), EngineVersion: "2.7", Engine: model.GetCreateInstanceByEngineReqEngineEnum().KAFKA, Description: &descriptionCreateInstanceByEngineReq, Name: "kafka-test", } response, err := client.CreatePostPaidKafkaInstance(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
Creating a yearly/monthly Kafka instance whose version is 2.7, specifications are 2 vCPUs | 4 GB x 3, and storage space is 300 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" kafka "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/kafka/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 := kafka.NewKafkaClient( kafka.KafkaClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreatePostPaidKafkaInstanceRequest{} 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, } keyTags:= "aaa" valueTags:= "111" var listTagsbody = []model.TagEntity{ { Key: &keyTags, Value: &valueTags, }, } var listSaslEnabledMechanismsbody = []model.CreateInstanceByEngineReqSaslEnabledMechanisms{ model.GetCreateInstanceByEngineReqSaslEnabledMechanismsEnum().SCRAM_SHA_512, } var listTenantIpsbody = []string{ "127.xx.xx.x", "127.xx.xx.x", "127.xx.xx.x", } var listAvailableZonesbody = []string{ "********706d4c1fb0eb72f0********", } vpcClientPlainCreateInstanceByEngineReq:= true archTypeCreateInstanceByEngineReq:= "X86" enterpriseProjectIdCreateInstanceByEngineReq:= "0" enableAutoTopicCreateInstanceByEngineReq:= true retentionPolicyCreateInstanceByEngineReq:= model.GetCreateInstanceByEngineReqRetentionPolicyEnum().TIME_BASE kafkaSecurityProtocolCreateInstanceByEngineReq:= "SASL_SSL" sslEnableCreateInstanceByEngineReq:= true publicipIdCreateInstanceByEngineReq:= "********-88fc-4a8c-86d0-************,********-16af-455d-8d54-************,********-3d69-4367-95ab-************" enablePublicipCreateInstanceByEngineReq:= true passwordCreateInstanceByEngineReq:= "********" accessUserCreateInstanceByEngineReq:= "********" descriptionCreateInstanceByEngineReq:= "" request.Body = &model.CreateInstanceByEngineReq{ BssParam: bssParambody, VpcClientPlain: &vpcClientPlainCreateInstanceByEngineReq, ArchType: &archTypeCreateInstanceByEngineReq, Tags: &listTagsbody, EnterpriseProjectId: &enterpriseProjectIdCreateInstanceByEngineReq, StorageSpecCode: model.GetCreateInstanceByEngineReqStorageSpecCodeEnum().DMS_PHYSICAL_STORAGE_ULTRA, EnableAutoTopic: &enableAutoTopicCreateInstanceByEngineReq, RetentionPolicy: &retentionPolicyCreateInstanceByEngineReq, SaslEnabledMechanisms: &listSaslEnabledMechanismsbody, KafkaSecurityProtocol: &kafkaSecurityProtocolCreateInstanceByEngineReq, SslEnable: &sslEnableCreateInstanceByEngineReq, PublicipId: &publicipIdCreateInstanceByEngineReq, TenantIps: &listTenantIpsbody, EnablePublicip: &enablePublicipCreateInstanceByEngineReq, ProductId: "c6.2u4g.cluster", AvailableZones: listAvailableZonesbody, SubnetId: "********-8fbf-4438-ba71-************", SecurityGroupId: "********-e073-4aad-991f-************", VpcId: "********-9b4a-44c5-a964-************", Password: &passwordCreateInstanceByEngineReq, AccessUser: &accessUserCreateInstanceByEngineReq, StorageSpace: int32(300), BrokerNum: int32(3), EngineVersion: "2.7", Engine: model.GetCreateInstanceByEngineReqEngineEnum().KAFKA, Description: &descriptionCreateInstanceByEngineReq, Name: "kafka-test1", } response, err := client.CreatePostPaidKafkaInstance(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