Todos os produtos
Search
Central de documentação

Resource Orchestration Service:ALIYUN::IOT::Rule

Última atualização: Sep 21, 2026

O ALIYUN::IOT::Rule crie uma regra para um tópico específico.

Sintaxe

{
  "Type": "ALIYUN::IOT::Rule",
  "Properties": {
    "TopicType": Integer,
    "IotInstanceId": String,
    "ResourceGroupId": String,
    "ShortTopic": String,
    "Select": String,
    "DataType": String,
    "RuleDesc": String,
    "Where": String,
    "ProductKey": String,
    "RuleAction": List,
    "StartRule": Boolean,
    "Name": String
  }
}

Propriedades

Propriedade Tipo Obrigatório Editável Descrição Restrição
TopicType Integer Não Sim O tipo do tópico. Valores válidos:
  • 0: o tópico de comunicação baseado na Thing Specification Language (TSL) ou o tópico de comunicação básica; especifique o tópico no parâmetro ShortTopic, como o tópico usado para que você envie o status de lotes de atualização OTA.
  • 1: o tópico personalizado.
  • 2: o tópico usado para enviar alterações de status do dispositivo. Formato: /as/mqtt/status/${productKey}/${deviceName}.
IotInstanceId String Não Não O ID da instância. Este parâmetro é obrigatório para instâncias Enterprise Edition, mas é opcional para instâncias públicas.
ResourceGroupId String Não Não O ID do grupo de recursos. Nenhuma
ShortTopic String Não Sim O tópico ao qual a regra se aplica. Formato: ${deviceName}/topicShortName. ${deviceName} indica o nome do dispositivo e topicShortName indica o nome personalizado do tópico.
Select String Não Sim A instrução SQL SELECT a ser executada. Para mais informações, consulte SQL expressions e selecione os campos necessários. Por favor, defina este parâmetro como o conteúdo que segue a palavra-chave SELECT. Por exemplo, se a instrução SELECT for SELECT a,b,c, defina este parâmetro como a,b,c.
DataType String Não Não O formato dos dados que a regra processa. O valor deste parâmetro deve ser idêntico ao formato dos dados do dispositivo a serem processados. Valor padrão: JSON. Valores válidos:
  • JSON
  • BINARY
    Nota Ao definir este parâmetro como BINARY, você não poderá definir o parâmetro TopicType como 0 nem encaminhar dados para o armazenamento de dados de séries temporais na instância, Time Series Database (TSDB), Tablestore ou ApsaraDB RDS.
RuleDesc String Não Sim A descrição da regra. Por favor, atualize este campo se necessário. A descrição pode ter até 100 caracteres.
Where String Não Sim A condição usada para acionar a regra. Para mais informações, consulte SQL expressions. Por favor, defina este parâmetro como o conteúdo que segue a palavra-chave WHERE. Por exemplo, se a instrução WHERE for WHERE a>10, defina este parâmetro como a>10.
ProductKey String Não Não O identificador exclusivo do product ao qual a regra se aplica. Por favor, visualize o product. Nenhuma
RuleAction List Não Sim A ação da regra. Para mais informações, consulte RuleAction properties.
StartRule Boolean Não Sim Define se a regra deve ser ativada. Se true, ative a regra. Valores válidos:
  • true
  • false
Name String Sim Sim O nome da regra. O nome deve ter de 1 a 30 bytes e pode conter letras, dígitos, hifens (-) e sublinhados (_).

Sintaxe de RuleAction

"RuleAction": [
  {
    "ErrorActionFlag": String,
    "Configuration": String,
    "Type": String
  }
] 

Propriedades de RuleAction

Propriedade Tipo Obrigatório Editável Descrição Restrição
ErrorActionFlag String Não Não Define se a ação da regra encaminha dados de operações com erro. Esses dados são gerados quando o mecanismo de regras falha ao encaminhar dados do tópico da IoT Platform para o service de cloud de destino. Uma falha no encaminhamento indica que as tentativas de reenvio também falharam. Valores válidos:
  • true
  • false
Configuration String Sim Não As configurações da ação da regra. Defina o valor como uma string JSON. Para mais informações, consulte CreateRuleAction.
Type String Sim Não O tipo da ação da regra. Para mais informações, consulte CreateRuleAction.

Parâmetros de resposta

Fn::GetAtt

  • RuleId: o ID da regra.

  • ActionId: o ID da ação da regra.

Exemplos

formato JSON

{
 "ROSTemplateFormatVersion": "2015-09-01",
 "Parameters": {
  "TopicType": {
   "Type": "Number",
   "Description": "0: The topic is a basic communication topic or TSL-based communication topic.\n1: The topic is a custom topic.\n2: The topic is used to submit device status changes. Syntax: /as/mqtt/status/${productKey}/${deviceName}."
  },
  "IotInstanceId": {
   "Type": "String",
   "Description": "The ID of the instance. This parameter is not required for public instances. However,\nthe parameter is required for the instances that you have purchased."
  },
  "ResourceGroupId": {
   "Type": "String",
   "Description": "The ID of the resource group to which the rule is assigned. You can view the resource\ngroup information in the Resource Management console.\nIf you do not specify this parameter, the rule is assigned to the default resource\ngroup."
  },
  "RuleAction": {
   "Type": "Json",
   "Description": "",
   "MinLength": 1,
   "MaxLength": 10
  },
  "ShortTopic": {
   "Type": "String",
   "Description": "The topic to which this rule is applied. Syntax: ${deviceName}/topicShortName. ${deviceName}specifies the name of the device, and topicShortNamespecifies the custom name of the topic.\nBasic communication topics or Thing Specification Language (TSL)-based communication\ntopics. Syntax: ${deviceName}/topicShortName. You can replace ${deviceName} with the + wildcard. The wildcard indicates that the topic applies to all devices under the\nproduct. Valid values of topicShortName:\n/thing/event/property/post: submits the property data of a device.\n/thing/event/${tsl.event.identifier}/post: submits the event data of a device.${tsl.event.identifier} specifies the identifier of an event in the TSL.\n/thing/lifecycle: submits device lifecycle changes.\n/thing/downlink/reply/message: sends a response to a request from IoT Platform.\n/thing/list/found: submits the data when a gateway detects a new sub-device.\n/thing/topo/lifecycle: submits device topology changes.\n/thing/event/property/history/post: submits historical property data of a device.\n/thing/event/${tsl.event.identifier}/post: submits the historical event data of a device.${tsl.event.identifier}specifies the identifier of an event in the TSL.\n/ota/upgrade: submits OTA update status.\n/ota/version/post: submits OTA module versions.\n/thing/deviceinfo/update: submits device tag changes.\n/edge/driver/${driver_id}/point_post: submits pass-through data from Link IoT Edge.${driver_id} specifies the ID of the driver that a device uses to access Link IoT Edge.\n${packageId}/${jobId}/ota/job/status: submits the status of OTA update batches. This topic is a basic communication topic.\n${packageId}specifies the ID of the firmware. ${jobId}specifies the ID of the update batch.\nCustom topics. Example:${deviceName}/user/get.\nYou can call theQueryProductTopicoperation to view all custom topics of the product.\nWhen you specify a custom topic, you can use the + and # wildcards.\nYou can replace ${deviceName} with the+ wildcard. The wildcard indicates that the topic applies to all devices under the\nproduct.\nYou can replace the fields that follow ${deviceName} with /user/#. The # wildcard indicates that the topic applies whatever values are specified for the fields that\nfollow/user.\nFor more information about how to use wildcards, see Wildcards in topics.\nTopic that is used to submit device status changes: ${deviceName}.\nYou can use the+wildcard. In this case, the status changes of all devices under the product are submitted."
  },
  "Select": {
   "Type": "String",
   "Description": "The SQL SELECT statement that you want to execute. For more information, seeSQL expressions.\nNote Specify the fields that follow the Select keyword for this parameter. For example, if the Select statement is Select a,b,c, specify a,b,c for this parameter."
  },
  "StartRule": {
   "Type": "Boolean",
   "Description": "Start the rule. The rule at least contains one rule action with normal data forward. ",
   "AllowedValues": [
    "True",
    "true",
    "False",
    "false"
   ]
  },
  "DataType": {
   "Type": "String",
   "Description": "The format of the data to be processed by the rule. You must specify the format of\ndevice data to be processed for this parameter. Valid values:\nJSON: JSON data\nBINARY: binary data\nNote If you specifyBINARY, you cannot set the TopicType parameter to 0 and forward data to Table Store, Time Series Database (TSDB), or ApsaradDB\nfor RDS.\nDefault value: JSON.",
   "AllowedValues": [
    "BINARY",
    "JSON"
   ]
  },
  "RuleDesc": {
   "Type": "String",
   "Description": "The description of the rule. The description can be up to 100 characters in length.\nEach Chinese symbol occupies 1 characters."
  },
  "Where": {
   "Type": "String",
   "Description": "The condition that is used to trigger the rule. For more information, seeSQL expressions.\nNote Specify the fields that follow theWherekeyword for this parameter. For example, if the Where statement is Where a>10, specify a>10 for this parameter."
  },
  "ProductKey": {
   "Type": "String",
   "Description": "The ProductKey of the product to which the rule applies."
  },
  "Name": {
   "Type": "String",
   "Description": "The name of the rule. The name must be 1 to 30 characters in length and can contain\nEnglish letters, digits, underscores (_), and hyphens (-). Chinese language is also\nsupported. Each Chinese symbol occupies 2 characters."
  }
 },
 "Resources": {
  "Rule": {
   "Type": "ALIYUN::IOT::Rule",
   "Properties": {
    "TopicType": {
     "Ref": "TopicType"
    },
    "IotInstanceId": {
     "Ref": "IotInstanceId"
    },
    "ResourceGroupId": {
     "Ref": "ResourceGroupId"
    },
    "RuleAction": {
     "Ref": "RuleAction"
    },
    "ShortTopic": {
     "Ref": "ShortTopic"
    },
    "Select": {
     "Ref": "Select"
    },
    "StartRule": {
     "Ref": "StartRule"
    },
    "DataType": {
     "Ref": "DataType"
    },
    "RuleDesc": {
     "Ref": "RuleDesc"
    },
    "Where": {
     "Ref": "Where"
    },
    "ProductKey": {
     "Ref": "ProductKey"
    },
    "Name": {
     "Ref": "Name"
    }
   }
  }
 },
 "Outputs": {
  "ActionId": {
   "Description": "The ID of the rule action. ",
   "Value": {
    "Fn::GetAtt": [
     "Rule",
     "ActionId"
    ]
   }
  },
  "RuleId": {
   "Description": "The ID of the rule. ",
   "Value": {
    "Fn::GetAtt": [
     "Rule",
     "RuleId"
    ]
   }
  }
 }
}

formato YAML

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
 TopicType:
  Type: Number
  Description: >-
   0: The topic is a basic communication topic or TSL-based communication
   topic.

   1: The topic is a custom topic.

   2: The topic is used to submit device status changes. Syntax:
   /as/mqtt/status/${productKey}/${deviceName}.
 IotInstanceId:
  Type: String
  Description: >-
   The ID of the instance. This parameter is not required for public
   instances. However,

   the parameter is required for the instances that you have purchased.
 ResourceGroupId:
  Type: String
  Description: >-
   The ID of the resource group to which the rule is assigned. You can view
   the resource

   group information in the Resource Management console.

   If you do not specify this parameter, the rule is assigned to the default
   resource

   group.
 RuleAction:
  Type: Json
  Description: ''
  MinLength: 1
  MaxLength: 10
 ShortTopic:
  Type: String
  Description: >-
   The topic to which this rule is applied. Syntax:
   ${deviceName}/topicShortName. ${deviceName}specifies the name of the
   device, and topicShortNamespecifies the custom name of the topic.

   Basic communication topics or Thing Specification Language (TSL)-based
   communication

   topics. Syntax: ${deviceName}/topicShortName. You can replace
   ${deviceName} with the + wildcard. The wildcard indicates that the topic
   applies to all devices under the

   product. Valid values of topicShortName:

   /thing/event/property/post: submits the property data of a device.

   /thing/event/${tsl.event.identifier}/post: submits the event data of a
   device.${tsl.event.identifier} specifies the identifier of an event in the
   TSL.

   /thing/lifecycle: submits device lifecycle changes.

   /thing/downlink/reply/message: sends a response to a request from IoT
   Platform.

   /thing/list/found: submits the data when a gateway detects a new
   sub-device.

   /thing/topo/lifecycle: submits device topology changes.

   /thing/event/property/history/post: submits historical property data of a
   device.

   /thing/event/${tsl.event.identifier}/post: submits the historical event
   data of a device.${tsl.event.identifier}specifies the identifier of an
   event in the TSL.

   /ota/upgrade: submits OTA update status.

   /ota/version/post: submits OTA module versions.

   /thing/deviceinfo/update: submits device tag changes.

   /edge/driver/${driver_id}/point_post: submits pass-through data from Link
   IoT Edge.${driver_id} specifies the ID of the driver that a device uses to
   access Link IoT Edge.

   ${packageId}/${jobId}/ota/job/status: submits the status of OTA update
   batches. This topic is a basic communication topic.

   ${packageId}specifies the ID of the firmware. ${jobId}specifies the ID of
   the update batch.

   Custom topics. Example:${deviceName}/user/get.

   You can call theQueryProductTopicoperation to view all custom topics of
   the product.

   When you specify a custom topic, you can use the + and # wildcards.

   You can replace ${deviceName} with the+ wildcard. The wildcard indicates
   that the topic applies to all devices under the

   product.

   You can replace the fields that follow ${deviceName} with /user/#. The #
   wildcard indicates that the topic applies whatever values are specified
   for the fields that

   follow/user.

   For more information about how to use wildcards, see Wildcards in topics.

   Topic that is used to submit device status changes: ${deviceName}.

   You can use the+wildcard. In this case, the status changes of all devices
   under the product are submitted.
 Select:
  Type: String
  Description: >-
   The SQL SELECT statement that you want to execute. For more information,
   seeSQL expressions.

   Note Specify the fields that follow the Select keyword for this parameter.
   For example, if the Select statement is Select a,b,c, specify a,b,c for
   this parameter.
 StartRule:
  Type: Boolean
  Description: >-
   Start the rule. The rule at least contains one rule action with normal
   data forward.
  AllowedValues:
   - 'True'
   - 'true'
   - 'False'
   - 'false'
 DataType:
  Type: String
  Description: >-
   The format of the data to be processed by the rule. You must specify the
   format of

   device data to be processed for this parameter. Valid values:

   JSON: JSON data

   BINARY: binary data

   Note If you specifyBINARY, you cannot set the TopicType parameter to 0 and
   forward data to Table Store, Time Series Database (TSDB), or ApsaradDB

   for RDS.

   Default value: JSON.
  AllowedValues:
   - BINARY
   - JSON
 RuleDesc:
  Type: String
  Description: >-
   The description of the rule. The description can be up to 100 characters
   in length.

   Each Chinese symbol occupies 1 characters.
 Where:
  Type: String
  Description: >-
   The condition that is used to trigger the rule. For more information,
   seeSQL expressions.

   Note Specify the fields that follow theWherekeyword for this parameter.
   For example, if the Where statement is Where a>10, specify a>10 for this
   parameter.
 ProductKey:
  Type: String
  Description: The ProductKey of the product to which the rule applies.
 Name:
  Type: String
  Description: >-
   The name of the rule. The name must be 1 to 30 characters in length and
   can contain

   English letters, digits, underscores (_), and hyphens (-). Chinese
   language is also

   supported. Each Chinese symbol occupies 2 characters.
Resources:
 Rule:
  Type: 'ALIYUN::IOT::Rule'
  Properties:
   TopicType:
    Ref: TopicType
   IotInstanceId:
    Ref: IotInstanceId
   ResourceGroupId:
    Ref: ResourceGroupId
   RuleAction:
    Ref: RuleAction
   ShortTopic:
    Ref: ShortTopic
   Select:
    Ref: Select
   StartRule:
    Ref: StartRule
   DataType:
    Ref: DataType
   RuleDesc:
    Ref: RuleDesc
   Where:
    Ref: Where
   ProductKey:
    Ref: ProductKey
   Name:
    Ref: Name
Outputs:
 ActionId:
  Description: 'The ID of the rule action. '
  Value:
   'Fn::GetAtt':
    - Rule
    - ActionId
 RuleId:
  Description: 'The ID of the rule. '
  Value:
   'Fn::GetAtt':
    - Rule
    - RuleId