

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 物件類型
<a name="thing-types"></a>

物件類型能讓您存放與相同物件類型關聯之所有物件通用的描述和組態資訊。如此可簡化登錄檔中物件的管理。例如，您可以定義 LightBulb 物件類型。所有與 LightBulb 物件類型關聯的物件具有同一組屬性：序號、製造商、瓦特數。當您建立 LightBulb 類型的物件 (或是變更現有物件的類型為 LightBulb)，可以指定在 LightBulb 物件類型中所定義的每個屬性之值。

雖然物件類型為選用，但使用時可讓您探索物件更輕鬆。
+ 有物件類型的物件最多可具有 50 個屬性。
+ 無物件類型的物件最多可具有三個屬性。
+ 一個物件只能與一個物件類型建立關聯。
+ 在您的帳戶中，可以建立的物件類型數量不限。

物件類型建立之後，您就無法變更其名稱。您可以隨時棄用物件類型，避免新的物件與其建立關聯。您也可以刪除未和任何物件關聯的物件類型。

**Topics**
+ [建立物件類型](create-thing-type.md)
+ [列出物件類型](list-thing-types.md)
+ [描述物件類型](describe-thing-type.md)
+ [將物件類型與物件建立關聯](associate-thing-type.md)
+ [更新物件類型](update-thing-type.md)
+ [棄用物件類型](deprecate-thing-type.md)
+ [刪除物件類型](delete-thing-types.md)

# 建立物件類型
<a name="create-thing-type"></a>

您可以使用 **CreateThingType** 命令來建立物件類型：

```
$ aws iot create-thing-type 

                --thing-type-name "LightBulb" --thing-type-properties "thingTypeDescription=light bulb type, searchableAttributes=wattage,model"
```

**CreateThingType** 命令的回應會包含物件類型及其 ARN：

```
{
    "thingTypeName": "LightBulb",
    "thingTypeId": "df9c2d8c-894d-46a9-8192-9068d01b2886",
    "thingTypeArn": "arn:aws:iot:us-west-2:123456789012:thingtype/LightBulb"
}
```

# 列出物件類型
<a name="list-thing-types"></a>

您可以使用 **ListThingTypes** 命令列出物件類型：

```
$ aws iot list-thing-types
```

**ListThingTypes** 命令會傳回 中定義的物件類型清單 AWS 帳戶：

```
{
    "thingTypes": [
        {
            "thingTypeName": "LightBulb",
            "thingTypeProperties": {
                "searchableAttributes": [
                    "wattage",
                    "model"
                ],
                "thingTypeDescription": "light bulb type"
            },
            "thingTypeMetadata": {
                "deprecated": false,
                "creationDate": 1468423800950
            }
        }
    ]
}
```

# 描述物件類型
<a name="describe-thing-type"></a>

您可以使用 **DescribeThingType** 命令獲得關於物件類型的資訊：

```
$ aws iot describe-thing-type --thing-type-name "LightBulb"
```

**DescribeThingType** 命令會傳回關於指定類型的資訊：

```
{
    "thingTypeProperties": {
        "searchableAttributes": [
            "model", 
            "wattage"
        ], 
        "thingTypeDescription": "light bulb type"
    }, 
    "thingTypeId": "df9c2d8c-894d-46a9-8192-9068d01b2886", 
    "thingTypeArn": "arn:aws:iot:us-west-2:123456789012:thingtype/LightBulb", 
    "thingTypeName": "LightBulb", 
    "thingTypeMetadata": {
        "deprecated": false, 
        "creationDate": 1544466338.399
    }
}
```

# 將物件類型與物件建立關聯
<a name="associate-thing-type"></a>

在建立物件時，您可以使用 **CreateThing** 命令指定物件類型：

```
$ aws iot create-thing --thing-name "MyLightBulb" --thing-type-name "LightBulb" --attribute-payload "{\"attributes\": {\"wattage\":\"75\", \"model\":\"123\"}}"
```

您可以隨時使用 **UpdateThing** 命令變更與物件關聯的物件類型：

```
$ aws iot update-thing --thing-name "MyLightBulb"
                --thing-type-name "LightBulb" --attribute-payload  "{\"attributes\": {\"wattage\":\"75\", \"model\":\"123\"}}"
```

您也可以使用 **UpdateThing** 命令取消物件與物件類型的關聯。

# 更新物件類型
<a name="update-thing-type"></a>

您可以在建立物件時使用 **UpdateThingType**命令來更新物件類型：

```
$ aws iot create-thing --thing-name "MyLightBulb" --thing-type-name "LightBulb" --attribute-payload "{\"attributes\": {\"wattage\":\"75\", \"model\":\"123\"}}"
```

您可以隨時使用 **UpdateThing** 命令變更與物件關聯的物件類型：

```
$ aws iot update-thing --thing-name "MyLightBulb"
                --thing-type-name "LightBulb" --attribute-payload  "{\"attributes\": {\"wattage\":\"75\", \"model\":\"123\"}}"
```

您也可以使用 **UpdateThing** 命令取消物件與物件類型的關聯。

# 棄用物件類型
<a name="deprecate-thing-type"></a>

物件類型不可變。物件類型定義之後就無法變更。不過，您可以棄用物件類型，避免使用者將其與任何新物件建立關聯。所有與該物件類型關聯的現有物件都不會變更。

若要棄用物件類型，請使用 **DeprecateThingType** 命令：

```
$ aws iot deprecate-thing-type --thing-type-name "myThingType"
```

您可以使用 **DescribeThingType** 命令來查看結果：

```
$ aws iot describe-thing-type --thing-type-name "StopLight":
```

```
{
    "thingTypeName": "StopLight",
    "thingTypeProperties": {
        "searchableAttributes": [
            "wattage",
            "numOfLights",
            "model"
        ],
        "thingTypeDescription": "traffic light type",
    },
    "thingTypeMetadata": {
        "deprecated": true,
        "creationDate": 1468425854308,
        "deprecationDate": 1468446026349
    }
}
```

棄用物件類型是可逆的操作。您可以使用 `--undo-deprecate` 旗標以及 **DeprecateThingType** CLI 命令來取消棄用：

```
$ aws iot deprecate-thing-type --thing-type-name "myThingType" --undo-deprecate
```

您可以使用 **DescribeThingType** CLI 命令查看結果：

```
$ aws iot describe-thing-type --thing-type-name "StopLight":
```

```
{
    "thingTypeName": "StopLight",
    "thingTypeArn": "arn:aws:iot:us-east-1:123456789012:thingtype/StopLight",
    "thingTypeId": "12345678abcdefgh12345678ijklmnop12345678"
    "thingTypeProperties": {
        "searchableAttributes": [
            "wattage",
            "numOfLights",
            "model"
        ],
        "thingTypeDescription": "traffic light type"
    },
    "thingTypeMetadata": {
        "deprecated": false,
        "creationDate": 1468425854308,
    }
}
```

# 刪除物件類型
<a name="delete-thing-types"></a>

物件類型只有在棄用後才能刪除。若要刪除物件類型，請使用 **DeleteThingType** 命令：

```
$ aws iot delete-thing-type --thing-type-name "StopLight"
```

**注意**  
刪除物件類型之前，請等待五分鐘後將其棄用。