更新时间:2024-09-24 GMT+08:00
分享

创建设备接入实例

功能介绍

用户可以调用此接口创建一个设备接入实例。支持的实例规格请参见产品规格说明

接口约束:

  • 请保证账户余额充足,此接口无法使用优惠券支付,在创建包年/包月实例时,若余额不足会创建一个待支付订单。

  • 若想使用优惠券,请将请求中的is_auto_pay字段设置为false,参考支付包年/包月产品订单进行支付,或者在华为云官网页面使用优惠券进行支付。

  • 如果您需要退订包年/包月资源,请参考退订包年/包月资源

调用方法

请参见如何调用API

URI

POST /v5/iot/{project_id}/iotda-instances

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数说明:项目ID。获取方法请参见 获取项目ID

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数说明:用户Token。通过调用IAM服务 获取IAM用户Token接口获取,接口返回的响应消息头中“X-Subject-Token”就是需要获取的用户Token。简要的获取方法样例请参见 Token认证

表3 请求Body参数

参数

是否必选

参数类型

描述

instance_type

String

参数说明:创建的实例类型。实例类型说明参见产品规格说明

取值范围

  • standard:标准版实例

  • enterprise:企业版实例

flavor

Flavor object

参数说明:设备接入实例的规格参数。

name

String

参数说明:实例名称

取值范围:由中文字符,英文字母、数字及“_”、“-”组成,且长度为[1-64]个字符。

charge_info

ChargeInfo object

参数说明:设备接入实例计费信息

description

String

参数说明:设备接入实例的描述信息。

取值范围:长度不超过256,只允许中文、字母、数字、以及_,,.。、&-等字符的组合

enterprise_project_id

String

参数说明:企业项目Id。此字段填写明确的企业项目Id或者0(表示默认企业项目Id)时支持企业项目特性。可以企业项目管理服务中获取。

取值范围:长度不超过36,由小写字母[a-f]、数字、连接符(-)的组成。

tags

Array of Tag objects

参数说明:设备接入实例的标签信息。

additional_params

AdditionalParams object

企业版附加参数信息。

表4 Flavor

参数

是否必选

参数类型

描述

type

String

参数说明:待创建设备接入实例的规格名称。详情请参见产品规格说明中的规格编码。

size

Integer

参数说明:待创建设备接入标准版实例的单元数量。详情请参见产品规格说明。当instance_type是standard时,该参数必填。

表5 ChargeInfo

参数

是否必选

参数类型

描述

charge_mode

String

参数说明:实例的付费方式。

取值范围

  • prePaid:包年/包月

  • postPaid:按需计费

period_type

String

参数说明:订购设备接入实例的周期类型(包年、包月等)。charge_mode为prePaid时生效,且为必选值。

取值范围

  • month:包月

  • year:包年

period_num

Integer

参数说明:订购设备接入实例的周期数。charge_mode为prePaid时生效,且为必选值。

取值范围:period_type=month(周期类型为月)时,取值为[1,9];period_type=year(周期类型为年)时,取值为[1,3]"。

is_auto_renew

Boolean

参数说明:创建包年/包月实例时可指定,表示是否自动续订,续订的周期和原周期相同,且续订时会自动支付。

取值范围

  • true:自动续订

  • false:默认值,不自动续订

is_auto_pay

Boolean

参数说明:创建包年/包月实例时可指定,表示是否自动从客户的账户中支付,此字段不影响自动续订的支付方式。

取值范围:true - 自动支付,从账户余额自动扣费; false - 默认值,只提交订单不支付。需要客户参考支付包年/包月产品订单进行支付,或者在华为云官网页面使用进行支付。

表6 Tag

参数

是否必选

参数类型

描述

key

String

参数说明:标签键,标签的键可用字母(包含中文)、数字、空格和以下字符:下划线(_)点(.)冒号(:)等号(=)加号(+)中划线(-)以及@,首尾不能有空格字符。

value

String

参数说明:标签值,可为空字符串和null,标签的值可用字母(包含中文)、数字、空格和以下字符:下划线(_)点(.)冒号(:)等号(=)加号(+)中划线(-)以及@。

表7 AdditionalParams

参数

是否必选

参数类型

描述

vpc_id

String

参数说明:企业版实例的VPCID。

subnet_id

String

参数说明:企业版实例的子网ID。

security_group_id

String

参数说明:企业版实例的安全组ID。请确保所选安全组已放通22端口(Linux SSH登录),3389端口(Windows远程登录)和ICMP协议(Ping)。

smn_topic_urn

String

参数说明:SMN的topic urn, 当企业版实例创建成功时,平台将通过该topic发送通知。

ciphering_algorithm

String

参数说明:实例支持的加密算法。

取值范围

  • COMMON_ALGORITHM: 通用加密算法(支持RSA,SHA256等国际通用的密码算法)

  • SM_ALGORITHM: 支持SM系列商密算法(支持SM2,SM3,SM4等国密算法)

port_info

Port object

企业版端口信息。创建企业版实例时必填。

表8 Port

参数

是否必选

参数类型

描述

app_https_port

Integer

参数说明:应用接入HTTPS协议端口,默认值:443。

app_amqps_port

Integer

参数说明:应用接入AMQP协议端口, 默认值:5671。

device_coap_port

Integer

参数说明:设备接入COAP协议端口, 默认值:5683。

device_coaps_port

Integer

参数说明:设备接入COAPS协议端口, 默认值:5684。

device_mqtt_port

Integer

参数说明:设备接入MQTT协议端口, 默认值:1883。

device_mqtts_port

Integer

参数说明:设备接入MQTTS协议端口, 默认值:8883。

device_https_port

Integer

参数说明:设备接入HTTPS协议端口, 默认值:443。

响应参数

状态码: 200

表9 响应Body参数

参数

参数类型

描述

instance_type

String

参数说明:实例类型。

取值范围

  • standard:标准版实例

  • enterprise:企业版实例

instance_id

String

参数说明:实例ID。

取值范围:长度不超过36,由小写字母[a-f]、数字、连接符(-)的组成。

name

String

参数说明:实例名称

取值范围:由中文字符,英文字母、数字及“_”、“-”组成,且长度为[1-64]个字符。

flavor

Flavor object

参数说明:设备接入实例的规格参数。

status

String

参数说明:实例状态。

取值范围

  • CREATING:实例正在创建

  • ACTIVE:实例正常

  • FROZEN:实例冻结

  • TRADING: 实例正在进行交易

  • MODIFYING:实例正在变更规格

  • FAILED:实例创建失败

charge_info

ChargeInfo object

参数说明:设备接入实例计费信息

description

String

参数说明:设备接入实例的描述信息。

取值范围:长度不超过256,只允许中文、字母、数字、以及_,,.。、&-等字符的组合。

enterprise_project_id

String

参数说明:企业项目Id。

tags

Array of Tag objects

参数说明: 设备接入实例的标签信息。如果实例有标签,则会有该字段,否则该字段为空。

order_id

String

参数说明:订单号,创建包年包月实例时返回该参数。查看订单详情请参考查询订单详情

additional_params

AdditionalParams object

企业版附加参数信息。

表10 Flavor

参数

参数类型

描述

type

String

参数说明:待创建设备接入实例的规格名称。详情请参见产品规格说明中的规格编码。

size

Integer

参数说明:待创建设备接入标准版实例的单元数量。详情请参见产品规格说明。当instance_type是standard时,该参数必填。

表11 ChargeInfo

参数

参数类型

描述

charge_mode

String

参数说明:实例的付费方式。

取值范围

  • prePaid:包年/包月

  • postPaid:按需计费

period_type

String

参数说明:订购设备接入实例的周期类型(包年、包月等)。charge_mode为prePaid时生效,且为必选值。

取值范围

  • month:包月

  • year:包年

period_num

Integer

参数说明:订购设备接入实例的周期数。charge_mode为prePaid时生效,且为必选值。

取值范围:period_type=month(周期类型为月)时,取值为[1,9];period_type=year(周期类型为年)时,取值为[1,3]"。

is_auto_renew

Boolean

参数说明:创建包年/包月实例时可指定,表示是否自动续订,续订的周期和原周期相同,且续订时会自动支付。

取值范围

  • true:自动续订

  • false:默认值,不自动续订

is_auto_pay

Boolean

参数说明:创建包年/包月实例时可指定,表示是否自动从客户的账户中支付,此字段不影响自动续订的支付方式。

取值范围:true - 自动支付,从账户余额自动扣费; false - 默认值,只提交订单不支付。需要客户参考支付包年/包月产品订单进行支付,或者在华为云官网页面使用进行支付。

表12 Tag

参数

参数类型

描述

key

String

参数说明:标签键,标签的键可用字母(包含中文)、数字、空格和以下字符:下划线(_)点(.)冒号(:)等号(=)加号(+)中划线(-)以及@,首尾不能有空格字符。

value

String

参数说明:标签值,可为空字符串和null,标签的值可用字母(包含中文)、数字、空格和以下字符:下划线(_)点(.)冒号(:)等号(=)加号(+)中划线(-)以及@。

表13 AdditionalParams

参数

参数类型

描述

vpc_id

String

参数说明:企业版实例的VPCID。

subnet_id

String

参数说明:企业版实例的子网ID。

security_group_id

String

参数说明:企业版实例的安全组ID。请确保所选安全组已放通22端口(Linux SSH登录),3389端口(Windows远程登录)和ICMP协议(Ping)。

smn_topic_urn

String

参数说明:SMN的topic urn, 当企业版实例创建成功时,平台将通过该topic发送通知。

ciphering_algorithm

String

参数说明:实例支持的加密算法。

取值范围

  • COMMON_ALGORITHM: 通用加密算法(支持RSA,SHA256等国际通用的密码算法)

  • SM_ALGORITHM: 支持SM系列商密算法(支持SM2,SM3,SM4等国密算法)

port_info

Port object

企业版端口信息。创建企业版实例时必填。

表14 Port

参数

参数类型

描述

app_https_port

Integer

参数说明:应用接入HTTPS协议端口,默认值:443。

app_amqps_port

Integer

参数说明:应用接入AMQP协议端口, 默认值:5671。

device_coap_port

Integer

参数说明:设备接入COAP协议端口, 默认值:5683。

device_coaps_port

Integer

参数说明:设备接入COAPS协议端口, 默认值:5684。

device_mqtt_port

Integer

参数说明:设备接入MQTT协议端口, 默认值:1883。

device_mqtts_port

Integer

参数说明:设备接入MQTTS协议端口, 默认值:8883。

device_https_port

Integer

参数说明:设备接入HTTPS协议端口, 默认值:443。

请求示例

  • 创建实例,实例规格标准版中频单元,单元个数为2,计费方式为包年。

    POST https://{endpoint}/v5/iot/{project_id}/iotda-instances
    
    {
      "instance_type" : "standard",
      "flavor" : {
        "type" : "iotda.standard.s1",
        "size" : 2
      },
      "name" : "iotda_instance",
      "charge_info" : {
        "charge_mode" : "prePaid",
        "period_type" : "year",
        "period_num" : 1,
        "is_auto_renew" : "true",
        "is_auto_pay" : "false"
      },
      "description" : "IoTDA instance for production.",
      "enterprise_project_id" : "d22e47e9-cfad-4254-8a29-d2a56a07681d",
      "tags" : [ {
        "key" : "testTagName",
        "value" : "testTagValue"
      } ]
    }
  • 创建实例,实例规格标准版中频单元,单元个数为2,计费方式为按需计费。

    POST https://{endpoint}/v5/iot/{project_id}/iotda-instances
    
    {
      "instance_type" : "standard",
      "flavor" : {
        "type" : "iotda.standard.s2",
        "size" : 2
      },
      "name" : "iotda_instance",
      "charge_info" : {
        "charge_mode" : "postPaid"
      },
      "description" : "IoTDA instance for production.",
      "enterprise_project_id" : "d22e47e9-cfad-4254-8a29-d2a56a07681d"
    }
  • 创建实例,实例规格为企业版实例,计费方式为包年。

    POST https://{endpoint}/v5/iot/{project_id}/iotda-instances
    
    {
      "instance_type" : "enterprise",
      "flavor" : {
        "type" : "iotda.enterprise.1000tps.10wonlinedevice"
      },
      "name" : "iotda_enterprise_instance",
      "charge_info" : {
        "charge_mode" : "prePaid",
        "period_type" : "year",
        "period_num" : 1,
        "is_auto_renew" : "true",
        "is_auto_pay" : "false"
      },
      "description" : "IoTDA instance for production.",
      "enterprise_project_id" : "d22e47e9-cfad-4254-8a29-d2a56a07681d",
      "additional_params" : {
        "vpc_id" : "40926909-d411-45dd-a8b4-1ebc36512345",
        "subnet_id" : "088c7d8a-f49e-4f5f-bd33-ce9b6b712345",
        "security_group_id" : "55980b43-f006-4dbf-ab58-9b0d9e712345",
        "smn_topic_urn" : "urn:smn:cn-north-7:08aaee8ae000d5182f26c00199812345:iotda_instance_create",
        "ciphering_algorithm" : "COMMON_ALGORITHM",
        "port_info" : {
          "app_https_port" : "443",
          "app_amqps_port" : "5671",
          "device_coap_port" : "5683",
          "device_coaps_port" : "5684",
          "device_mqtt_port" : "1883",
          "device_mqtts_port" : "8883",
          "device_https_port" : "443"
        }
      }
    }

响应示例

状态码: 200

OK

{
  "instance_type" : "standard",
  "instance_id" : "8561675c-d8a3-4956-9884-9cf9cbdd3134",
  "flavor" : {
    "type" : "iotda.standard.s2",
    "size" : 2
  },
  "status" : "CREATING",
  "charge_info" : {
    "charge_mode" : "prePaid",
    "period_type" : "year",
    "period_num" : 1,
    "is_auto_renew" : true,
    "is_auto_pay" : false
  },
  "description" : "IoTDA instance for production.",
  "enterprise_project_id" : "d22e47e9-cfad-4254-8a29-d2a56a07681d",
  "tags" : [ {
    "key" : "testTagName",
    "value" : "testTagValue"
  } ],
  "order_id" : "CS22121614500ABCD",
  "additional_params" : null
}

SDK代码示例

SDK代码示例如下。

  • 创建实例,实例规格标准版中频单元,单元个数为2,计费方式为包年。

     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
    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.iotdm.v5.region.IoTDMRegion;
    import com.huaweicloud.sdk.iotdm.v5.*;
    import com.huaweicloud.sdk.iotdm.v5.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateInstanceSolution {
    
        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);
    
            IoTDMClient client = IoTDMClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(IoTDMRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateInstanceRequest request = new CreateInstanceRequest();
            CreateInstance body = new CreateInstance();
            List<Tag> listbodyTags = new ArrayList<>();
            listbodyTags.add(
                new Tag()
                    .withKey("testTagName")
                    .withValue("testTagValue")
            );
            ChargeInfo chargeInfobody = new ChargeInfo();
            chargeInfobody.withChargeMode("prePaid")
                .withPeriodType("year")
                .withPeriodNum(1)
                .withIsAutoRenew(true)
                .withIsAutoPay(false);
            Flavor flavorbody = new Flavor();
            flavorbody.withType("iotda.standard.s1")
                .withSize(2);
            body.withTags(listbodyTags);
            body.withEnterpriseProjectId("d22e47e9-cfad-4254-8a29-d2a56a07681d");
            body.withDescription("IoTDA instance for production.");
            body.withChargeInfo(chargeInfobody);
            body.withName("iotda_instance");
            body.withFlavor(flavorbody);
            body.withInstanceType("standard");
            request.withBody(body);
            try {
                CreateInstanceResponse response = client.createInstance(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());
            }
        }
    }
    
  • 创建实例,实例规格标准版中频单元,单元个数为2,计费方式为按需计费。

     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
    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.iotdm.v5.region.IoTDMRegion;
    import com.huaweicloud.sdk.iotdm.v5.*;
    import com.huaweicloud.sdk.iotdm.v5.model.*;
    
    
    public class CreateInstanceSolution {
    
        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);
    
            IoTDMClient client = IoTDMClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(IoTDMRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateInstanceRequest request = new CreateInstanceRequest();
            CreateInstance body = new CreateInstance();
            ChargeInfo chargeInfobody = new ChargeInfo();
            chargeInfobody.withChargeMode("postPaid");
            Flavor flavorbody = new Flavor();
            flavorbody.withType("iotda.standard.s2")
                .withSize(2);
            body.withEnterpriseProjectId("d22e47e9-cfad-4254-8a29-d2a56a07681d");
            body.withDescription("IoTDA instance for production.");
            body.withChargeInfo(chargeInfobody);
            body.withName("iotda_instance");
            body.withFlavor(flavorbody);
            body.withInstanceType("standard");
            request.withBody(body);
            try {
                CreateInstanceResponse response = client.createInstance(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());
            }
        }
    }
    
  • 创建实例,实例规格为企业版实例,计费方式为包年。

     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
    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.iotdm.v5.region.IoTDMRegion;
    import com.huaweicloud.sdk.iotdm.v5.*;
    import com.huaweicloud.sdk.iotdm.v5.model.*;
    
    
    public class CreateInstanceSolution {
    
        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);
    
            IoTDMClient client = IoTDMClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(IoTDMRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateInstanceRequest request = new CreateInstanceRequest();
            CreateInstance body = new CreateInstance();
            Port portInfoAdditionalParams = new Port();
            portInfoAdditionalParams.withAppHttpsPort(443)
                .withAppAmqpsPort(5671)
                .withDeviceCoapPort(5683)
                .withDeviceCoapsPort(5684)
                .withDeviceMqttPort(1883)
                .withDeviceMqttsPort(8883)
                .withDeviceHttpsPort(443);
            AdditionalParams additionalParamsbody = new AdditionalParams();
            additionalParamsbody.withVpcId("40926909-d411-45dd-a8b4-1ebc36512345")
                .withSubnetId("088c7d8a-f49e-4f5f-bd33-ce9b6b712345")
                .withSecurityGroupId("55980b43-f006-4dbf-ab58-9b0d9e712345")
                .withSmnTopicUrn("urn:smn:cn-north-7:08aaee8ae000d5182f26c00199812345:iotda_instance_create")
                .withCipheringAlgorithm("COMMON_ALGORITHM")
                .withPortInfo(portInfoAdditionalParams);
            ChargeInfo chargeInfobody = new ChargeInfo();
            chargeInfobody.withChargeMode("prePaid")
                .withPeriodType("year")
                .withPeriodNum(1)
                .withIsAutoRenew(true)
                .withIsAutoPay(false);
            Flavor flavorbody = new Flavor();
            flavorbody.withType("iotda.enterprise.1000tps.10wonlinedevice");
            body.withAdditionalParams(additionalParamsbody);
            body.withEnterpriseProjectId("d22e47e9-cfad-4254-8a29-d2a56a07681d");
            body.withDescription("IoTDA instance for production.");
            body.withChargeInfo(chargeInfobody);
            body.withName("iotda_enterprise_instance");
            body.withFlavor(flavorbody);
            body.withInstanceType("enterprise");
            request.withBody(body);
            try {
                CreateInstanceResponse response = client.createInstance(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());
            }
        }
    }
    
  • 创建实例,实例规格标准版中频单元,单元个数为2,计费方式为包年。

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkiotdm.v5.region.iotdm_region import IoTDMRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkiotdm.v5 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 = IoTDMClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(IoTDMRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateInstanceRequest()
            listTagsbody = [
                Tag(
                    key="testTagName",
                    value="testTagValue"
                )
            ]
            chargeInfobody = ChargeInfo(
                charge_mode="prePaid",
                period_type="year",
                period_num=1,
                is_auto_renew=True,
                is_auto_pay=False
            )
            flavorbody = Flavor(
                type="iotda.standard.s1",
                size=2
            )
            request.body = CreateInstance(
                tags=listTagsbody,
                enterprise_project_id="d22e47e9-cfad-4254-8a29-d2a56a07681d",
                description="IoTDA instance for production.",
                charge_info=chargeInfobody,
                name="iotda_instance",
                flavor=flavorbody,
                instance_type="standard"
            )
            response = client.create_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)
    
  • 创建实例,实例规格标准版中频单元,单元个数为2,计费方式为按需计费。

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkiotdm.v5.region.iotdm_region import IoTDMRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkiotdm.v5 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 = IoTDMClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(IoTDMRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateInstanceRequest()
            chargeInfobody = ChargeInfo(
                charge_mode="postPaid"
            )
            flavorbody = Flavor(
                type="iotda.standard.s2",
                size=2
            )
            request.body = CreateInstance(
                enterprise_project_id="d22e47e9-cfad-4254-8a29-d2a56a07681d",
                description="IoTDA instance for production.",
                charge_info=chargeInfobody,
                name="iotda_instance",
                flavor=flavorbody,
                instance_type="standard"
            )
            response = client.create_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)
    
  • 创建实例,实例规格为企业版实例,计费方式为包年。

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkiotdm.v5.region.iotdm_region import IoTDMRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkiotdm.v5 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 = IoTDMClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(IoTDMRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateInstanceRequest()
            portInfoAdditionalParams = Port(
                app_https_port=443,
                app_amqps_port=5671,
                device_coap_port=5683,
                device_coaps_port=5684,
                device_mqtt_port=1883,
                device_mqtts_port=8883,
                device_https_port=443
            )
            additionalParamsbody = AdditionalParams(
                vpc_id="40926909-d411-45dd-a8b4-1ebc36512345",
                subnet_id="088c7d8a-f49e-4f5f-bd33-ce9b6b712345",
                security_group_id="55980b43-f006-4dbf-ab58-9b0d9e712345",
                smn_topic_urn="urn:smn:cn-north-7:08aaee8ae000d5182f26c00199812345:iotda_instance_create",
                ciphering_algorithm="COMMON_ALGORITHM",
                port_info=portInfoAdditionalParams
            )
            chargeInfobody = ChargeInfo(
                charge_mode="prePaid",
                period_type="year",
                period_num=1,
                is_auto_renew=True,
                is_auto_pay=False
            )
            flavorbody = Flavor(
                type="iotda.enterprise.1000tps.10wonlinedevice"
            )
            request.body = CreateInstance(
                additional_params=additionalParamsbody,
                enterprise_project_id="d22e47e9-cfad-4254-8a29-d2a56a07681d",
                description="IoTDA instance for production.",
                charge_info=chargeInfobody,
                name="iotda_enterprise_instance",
                flavor=flavorbody,
                instance_type="enterprise"
            )
            response = client.create_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)
    
  • 创建实例,实例规格标准版中频单元,单元个数为2,计费方式为包年。

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        iotdm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/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 := iotdm.NewIoTDMClient(
            iotdm.IoTDMClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateInstanceRequest{}
    	valueTags:= "testTagValue"
    	var listTagsbody = []model.Tag{
            {
                Key: "testTagName",
                Value: &valueTags,
            },
        }
    	periodTypeChargeInfo:= "year"
    	periodNumChargeInfo:= int32(1)
    	isAutoRenewChargeInfo:= true
    	isAutoPayChargeInfo:= false
    	chargeInfobody := &model.ChargeInfo{
    		ChargeMode: "prePaid",
    		PeriodType: &periodTypeChargeInfo,
    		PeriodNum: &periodNumChargeInfo,
    		IsAutoRenew: &isAutoRenewChargeInfo,
    		IsAutoPay: &isAutoPayChargeInfo,
    	}
    	sizeFlavor:= int32(2)
    	flavorbody := &model.Flavor{
    		Type: "iotda.standard.s1",
    		Size: &sizeFlavor,
    	}
    	enterpriseProjectIdCreateInstance:= "d22e47e9-cfad-4254-8a29-d2a56a07681d"
    	descriptionCreateInstance:= "IoTDA instance for production."
    	request.Body = &model.CreateInstance{
    		Tags: &listTagsbody,
    		EnterpriseProjectId: &enterpriseProjectIdCreateInstance,
    		Description: &descriptionCreateInstance,
    		ChargeInfo: chargeInfobody,
    		Name: "iotda_instance",
    		Flavor: flavorbody,
    		InstanceType: "standard",
    	}
    	response, err := client.CreateInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建实例,实例规格标准版中频单元,单元个数为2,计费方式为按需计费。

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        iotdm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/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 := iotdm.NewIoTDMClient(
            iotdm.IoTDMClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateInstanceRequest{}
    	chargeInfobody := &model.ChargeInfo{
    		ChargeMode: "postPaid",
    	}
    	sizeFlavor:= int32(2)
    	flavorbody := &model.Flavor{
    		Type: "iotda.standard.s2",
    		Size: &sizeFlavor,
    	}
    	enterpriseProjectIdCreateInstance:= "d22e47e9-cfad-4254-8a29-d2a56a07681d"
    	descriptionCreateInstance:= "IoTDA instance for production."
    	request.Body = &model.CreateInstance{
    		EnterpriseProjectId: &enterpriseProjectIdCreateInstance,
    		Description: &descriptionCreateInstance,
    		ChargeInfo: chargeInfobody,
    		Name: "iotda_instance",
    		Flavor: flavorbody,
    		InstanceType: "standard",
    	}
    	response, err := client.CreateInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建实例,实例规格为企业版实例,计费方式为包年。

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        iotdm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/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 := iotdm.NewIoTDMClient(
            iotdm.IoTDMClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateInstanceRequest{}
    	appHttpsPortPortInfo:= int32(443)
    	appAmqpsPortPortInfo:= int32(5671)
    	deviceCoapPortPortInfo:= int32(5683)
    	deviceCoapsPortPortInfo:= int32(5684)
    	deviceMqttPortPortInfo:= int32(1883)
    	deviceMqttsPortPortInfo:= int32(8883)
    	deviceHttpsPortPortInfo:= int32(443)
    	portInfoAdditionalParams := &model.Port{
    		AppHttpsPort: &appHttpsPortPortInfo,
    		AppAmqpsPort: &appAmqpsPortPortInfo,
    		DeviceCoapPort: &deviceCoapPortPortInfo,
    		DeviceCoapsPort: &deviceCoapsPortPortInfo,
    		DeviceMqttPort: &deviceMqttPortPortInfo,
    		DeviceMqttsPort: &deviceMqttsPortPortInfo,
    		DeviceHttpsPort: &deviceHttpsPortPortInfo,
    	}
    	smnTopicUrnAdditionalParams:= "urn:smn:cn-north-7:08aaee8ae000d5182f26c00199812345:iotda_instance_create"
    	cipheringAlgorithmAdditionalParams:= "COMMON_ALGORITHM"
    	additionalParamsbody := &model.AdditionalParams{
    		VpcId: "40926909-d411-45dd-a8b4-1ebc36512345",
    		SubnetId: "088c7d8a-f49e-4f5f-bd33-ce9b6b712345",
    		SecurityGroupId: "55980b43-f006-4dbf-ab58-9b0d9e712345",
    		SmnTopicUrn: &smnTopicUrnAdditionalParams,
    		CipheringAlgorithm: &cipheringAlgorithmAdditionalParams,
    		PortInfo: portInfoAdditionalParams,
    	}
    	periodTypeChargeInfo:= "year"
    	periodNumChargeInfo:= int32(1)
    	isAutoRenewChargeInfo:= true
    	isAutoPayChargeInfo:= false
    	chargeInfobody := &model.ChargeInfo{
    		ChargeMode: "prePaid",
    		PeriodType: &periodTypeChargeInfo,
    		PeriodNum: &periodNumChargeInfo,
    		IsAutoRenew: &isAutoRenewChargeInfo,
    		IsAutoPay: &isAutoPayChargeInfo,
    	}
    	flavorbody := &model.Flavor{
    		Type: "iotda.enterprise.1000tps.10wonlinedevice",
    	}
    	enterpriseProjectIdCreateInstance:= "d22e47e9-cfad-4254-8a29-d2a56a07681d"
    	descriptionCreateInstance:= "IoTDA instance for production."
    	request.Body = &model.CreateInstance{
    		AdditionalParams: additionalParamsbody,
    		EnterpriseProjectId: &enterpriseProjectIdCreateInstance,
    		Description: &descriptionCreateInstance,
    		ChargeInfo: chargeInfobody,
    		Name: "iotda_enterprise_instance",
    		Flavor: flavorbody,
    		InstanceType: "enterprise",
    	}
    	response, err := client.CreateInstance(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

OK

400

Bad Request

401

Unauthorized

403

Forbidden

错误码

请参见错误码

相关文档