

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# レジストリを使用したモノの管理
<a name="thing-registry"></a>

 AWS IoT コンソール、 AWS IoT API、または AWS CLI を使用してレジストリを操作します。以下の各セクションでは、CLI を使用して Registry を操作する方法を示します。

**モノのオブジェクトに名前を付ける場合:**
+ モノの名前で個人を特定できる情報を使用しないでください。モノの名前は、暗号化されていない通信やレポートに表示されることがあります。

**Topics**
+ [モノの作成](create-thing.md)
+ [モノのリスト表示](list-things.md)
+ [モノを記述する](search-things.md)
+ [モノの更新](update-thing.md)
+ [モノの削除](delete-thing.md)
+ [モノにプリンシパルをアタッチする](attach-thing-principal.md)
+ [プリンシパルに関連付けられているモノを一覧表示する](list-principal-things.md)
+ [モノに関連付けられているプリンシパルを一覧表示する](list-thing-principals.md)
+ [プリンシパルに関連付けられているモノを一覧表示する (V2)](list-principal-things-v2.md)
+ [モノに関連付けられているプリンシパルを一覧表示する (V2)](list-thing-principals-v2.md)
+ [モノからプリンシパルをデタッチする](detach-thing-principal.md)

# モノの作成
<a name="create-thing"></a>

次のコマンドは、 CLI の コマンドを使用して AWS IoT **CreateThing**モノを作成する方法を示しています。モノの作成後に名前を変更することはできません。モノの名前を変更するには、新しいモノを作成して、新しい名前を付け、古いモノを削除します。

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

**CreateThing** コマンドを実行すると、新しいモノの名前と Amazon リソースネーム (ARN) が表示されます。

```
{
    "thingArn": "arn:aws:iot:us-east-1:123456789012:thing/MyLightBulb",
    "thingName": "MyLightBulb",
    "thingId": "12345678abcdefgh12345678ijklmnop12345678"
}
```

**注記**  
モノの名前に個人を特定できる情報を使用することはお勧めしません。

詳細については、「 AWS CLI コマンドリファレンス」の「[create-thing](https://docs.aws.amazon.com//cli/latest/reference/iot/create-thing.html)」を参照してください。

# モノのリスト表示
<a name="list-things"></a>

**ListThings** コマンドを使用すると、アカウント内のモノをすべてリスト表示できます。

```
$ aws iot list-things
```

```
{
    "things": [
       {
            "attributes": {
                "model": "123",
                "wattage": "75"
            },
            "version": 1,
            "thingName": "MyLightBulb"
        },
        {
            "attributes": {
                "numOfStates":"3"
             },
            "version": 11,
            "thingName": "MyWallSwitch"
        }
    ]
}
```

**ListThings** コマンドを使用して、特定のモノタイプのすべてのものを検索できます。

```
$  aws iot list-things --thing-type-name "LightBulb"
```

```
{
    "things": [
        {
            "thingTypeName": "LightBulb",
            "attributes": {
                "model": "123",
                "wattage": "75"
            },
            "version": 1,
            "thingName": "MyRGBLight"
        },
        {
            "thingTypeName": "LightBulb",
            "attributes": {
                "model": "123",
                "wattage": "75"
            },
            "version": 1,
            "thingName": "MySecondLightBulb"
        }
    ]
}
```

**ListThings** コマンドを使用して、特定の属性値を持つすべてのモノを検索できます。このコマンドは、最大 3 つの属性を検索します。

```
$  aws iot list-things --attribute-name "wattage" --attribute-value "75"
```

```
{
    "things": [
        {
            "thingTypeName": "StopLight",
            "attributes": {
                "model": "123",
                "wattage": "75"
            },
            "version": 3,
            "thingName": "MyLightBulb"
        },
        {
            "thingTypeName": "LightBulb",
            "attributes": {
                "model": "123",
                "wattage": "75"
            },
            "version": 1,
            "thingName": "MyRGBLight"
        },
        {
            "thingTypeName": "LightBulb",
            "attributes": {
                "model": "123",
                "wattage": "75"
            },
            "version": 1,
            "thingName": "MySecondLightBulb"
        }
    ]
}
```

詳細については、「 AWS CLI コマンドリファレンス」の「[list-things](https://docs.aws.amazon.com//cli/latest/reference/iot/list-things.html)」を参照してください。

# モノを記述する
<a name="search-things"></a>

**DescribeThing** コマンドを使用して、モノに関するより詳細な情報を表示できます。

```
$ aws iot describe-thing --thing-name "MyLightBulb"
{
    "version": 3,
    "thingName": "MyLightBulb",
    "thingArn": "arn:aws:iot:us-east-1:123456789012:thing/MyLightBulb",
    "thingId": "12345678abcdefgh12345678ijklmnop12345678",
    "defaultClientId": "MyLightBulb",
    "thingTypeName": "StopLight",
    "attributes": {
        "model": "123",
        "wattage": "75"
    }
}
```

インライン関数 を使用して、ルールエンジン内でこの API にアクセスすることもできます`get_registry_data()`。この関数を使用すると、 および `DescribeThing` `ListThingGroupsForThing` APIs を AWS IoT ルール内で直接呼び出すことで、モノのレジストリ情報 (属性、モノのタイプ、グループメンバーシップを含む) に動的にアクセスして利用でき、デバイスレジストリデータに基づいてリアルタイムのメッセージ処理とルーティングが可能になります。詳細については、「[https://docs.aws.amazon.com//iot/latest/developerguide/iot-sql-functions.html#iot-sql-function-get-registry_data](https://docs.aws.amazon.com//iot/latest/developerguide/iot-sql-functions.html#iot-sql-function-get-registry_data)」を参照してください。

詳細については、 AWS CLI 「 コマンドリファレンス」の[「describe-thing](https://docs.aws.amazon.com//cli/latest/reference/iot/describe-thing.html)」を参照してください。

# モノの更新
<a name="update-thing"></a>

**UpdateThing** コマンドを使用すると、モノを更新できます。このコマンドはモノの属性だけを更新します。モノの名前を変更することはできません。モノの名前を変更するには、新しいモノを作成して、新しい名前を付け、古いモノを削除します。

```
$ aws iot update-thing --thing-name "MyLightBulb" --attribute-payload "{\"attributes\": {\"wattage\":\"150\", \"model\":\"456\"}}"
```

**UpdateThing** コマンドでは、出力が生成されません。**DescribeThing** コマンドを使用して、結果を表示できます。

```
$ aws iot describe-thing --thing-name "MyLightBulb"
{
    "attributes": {
        "model": "456",
        "wattage": "150"
    },
    "version": 2,
    "thingName": "MyLightBulb"
}
```

詳細については、「 AWS CLI コマンドリファレンス」の「[update-thing](https://docs.aws.amazon.com//cli/latest/reference/iot/update-thing.html)」を参照してください。

# モノの削除
<a name="delete-thing"></a>

**DeleteThing** コマンドを使用すると、モノを削除できます。

```
$ aws iot delete-thing --thing-name "MyThing"
```

このコマンドは、削除が成功した場合、または存在しないモノが指定された場合、エラーなしで正常に終了します。

詳細については、「 AWS CLI コマンドリファレンス」の「[delete-thing](https://docs.aws.amazon.com//cli/latest/reference/iot/delete-thing.html)」を参照してください。

# モノにプリンシパルをアタッチする
<a name="attach-thing-principal"></a>

物理デバイスは、プリンシパルを使用して通信できます AWS IoT。プリンシパルには、X.509 証明書または Amazon Cognito ID を使用できます。証明書または Amazon Cognito ID をデバイスを表すレジストリ内のモノに関連付けるには、[attach-thing-principal](https://docs.aws.amazon.com//cli/latest/reference/iot/attach-thing-principal.html) コマンドを実行します。

[attach-thing-principal](https://docs.aws.amazon.com//cli/latest/reference/iot/attach-thing-principal.html) コマンドを使用して、証明書または Amazon Cognito ID をモノにアタッチする方法:

```
$ aws iot attach-thing-principal \
    --thing-name "MyLightBulb1" \
    --principal "arn:aws:iot:us-east-1:123456789012:cert/a0c01f5835079de0a7514643d68ef8414ab739a1e94ee4162977b02b12842847"
```

アタッチメントタイプ (排他的アタッチメント、または非排他的アタッチメント) を指定してモノに証明書をアタッチするには、[https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/attach-thing-principal.html](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/attach-thing-principal.html) コマンドを使用して、`--thing-principal-type` フィールドにタイプを指定します。排他的アタッチメントとは、IoT のモノが証明書にアタッチされている唯一のモノであり、他のモノにこの証明書を関連付けることはできません。非排他的アタッチメントとは、IoT のモノが証明書にアタッチされ、かつ、この証明書を他のモノにも関連付けることができることを意味します。詳細については、「[AWS IoT モノを MQTT クライアント接続に関連付ける](exclusive-thing.md)」を参照してください。

**注記**  
[AWS IoT モノを MQTT クライアント接続に関連付ける](exclusive-thing.md)機能では、プリンシパルとして使用できるのは X.509 証明書のみです。

```
$ aws iot attach-thing-principal \
    --thing-name "MyLightBulb2" \
    --principal "arn:aws:iot:us-east-1:123456789012:cert/a0c01f5835079de0a7514643d68ef8414ab739a1e94ee4162977b02b12842847" \
    --thing-principal-type "EXCLUSIVE_THING"
```

アタッチメントが成功した場合は、**AttachThingPrincipal** コマンドは出力を生成しません。アタッチメントを記述するには、list-thing-principals-v2 CLI コマンドを使用します。

詳細については、「*AWS IoT Core API リファレンス*」の「[AttachThingPrincipal](https://docs.aws.amazon.com//iot/latest/apireference/API_AttachThingPrincipal.html)」を参照してください。

# プリンシパルに関連付けられているモノを一覧表示する
<a name="list-principal-things"></a>

指定のプリンシパルに関連付けられているモノを一覧表示するには、[https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/list-principal-things.htmls](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/list-principal-things.htmls) コマンドを実行します。このコマンドでは、モノと証明書間のアタッチメントタイプは一覧に表示されない点に注意してください。アタッチメントタイプを一覧表示するには、[https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/list-principal-thingsv2.html](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/list-principal-thingsv2.html) コマンドを使用します。詳細については、「[プリンシパルに関連付けられているモノを一覧表示する (V2)](list-principal-things-v2.md)」を参照してください。

```
$ aws iot list-principal-things \
    --principal "arn:aws:iot:us-east-1:123456789012:cert/2e1eb273792174ec2b9bf4e9b37e6c6c692345499506002a35159767055278e8"
```

出力は次のようになります。

```
{
    "things": [
        "MyLightBulb1",
        "MyLightBulb2"
    ]
}
```

詳細については、「*AWS IoT Core API リファレンス*」の「[ListPrincipalThings](https://docs.aws.amazon.com//iot/latest/apireference/API_ListPrincipalThings.html)」を参照してください。

# モノに関連付けられているプリンシパルを一覧表示する
<a name="list-thing-principals"></a>

指定のモノに関連付けられているプリンシパルを一覧表示するには、[https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/list-thing-principals.html](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/list-thing-principals.html) コマンドを実行します。このコマンドでは、モノと証明書間のアタッチメントタイプは一覧に表示されない点に注意してください。アタッチメントタイプを一覧表示するには、[https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/list-thing-principalsv2.html](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/list-thing-principalsv2.html) コマンドを使用します。詳細については、「[モノに関連付けられているプリンシパルを一覧表示する (V2)](list-thing-principals-v2.md)」を参照してください。

```
$ aws iot list-thing-principals \
    --thing-name "MyLightBulb1"
```

出力は次のようになります。

```
{
    "principals": [
         "arn:aws:iot:us-east-1:123456789012:cert/2e1eb273792174ec2b9bf4e9b37e6c6c692345499506002a35159767055278e8",
         "arn:aws:iot:us-east-1:123456789012:cert/1a234b39b4b68278f2e9d84bf97eac2cbf4a1c28b23ea29a44559b9bcf8d395b"
    ]
}
```

詳細については、「*AWS IoT Core API リファレンス*」の「[ListThingPrincipals](https://docs.aws.amazon.com//iot/latest/apireference/API_ListThingPrincipals.html)」を参照してください。

# プリンシパルに関連付けられているモノを一覧表示する (V2)
<a name="list-principal-things-v2"></a>

指定の証明書に関連付けられているモノをアタッチメントタイプとともに一覧表示するには、[https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/list-principal-thingsv2.html](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/list-principal-thingsv2.html) コマンドを実行します。アタッチメントタイプは、証明書がモノにアタッチされる方式を指します。

```
$ aws iot list-principal-things-v2 \
    --principal "arn:aws:iot:us-east-1:123456789012:cert/2e1eb273792174ec2b9bf4e9b37e6c6c692345499506002a35159767055278e8"
```

出力は次のようになります。

```
{
    "PrincipalThingObjects": [
        {
            "thingPrincipalType": "NON_EXCLUSIVE_THING",
            "thing": "arn:aws:iot:us-east-1:123456789012:thing/thing_1"
        }, 
        {
            "thingPrincipalType": "NON_EXCLUSIVE_THING",
            "thing": "arn:aws:iot:us-east-1:123456789012:thing/thing_2"
        }

    ]
}
```

詳細については、「*AWS IoT Core API リファレンス*」の「[ListPrincipalThingsV2](https://docs.aws.amazon.com//iot/latest/apireference/API_ListPrincipalThingsV2.html)」を参照してください。

# モノに関連付けられているプリンシパルを一覧表示する (V2)
<a name="list-thing-principals-v2"></a>

指定のモノに関連付けられている証明書をアタッチメントタイプとともに一覧表示するには、[https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/list-thing-principalsv2.html](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/list-thing-principalsv2.html) コマンドを実行します。アタッチメントタイプは、証明書がモノにアタッチされる方式を指します。

```
$ aws iot list-thing-principals-v2 \
    --thing-name "thing_1"
```

出力は次のようになります。

```
{
    "ThingPrincipalObjects": [
        {
            "thingPrincipalType": "NON_EXCLUSIVE_THING",
            "principal": "arn:aws:iot:us-east-1:123456789012:cert/2e1eb273792174ec2b9bf4e9b37e6c6c692345499506002a35159767055278e8"
        },
        {
            "thingPrincipalType": "NON_EXCLUSIVE_THING",
            "principal": "arn:aws:iot:us-east-1:123456789012:cert/1a234b39b4b68278f2e9d84bf97eac2cbf4a1c28b23ea29a44559b9bcf8d395b"
        }
    ]
}
```

詳細については、「*AWS IoT Core API リファレンス*」の「[ListThingsPrincipalV2](https://docs.aws.amazon.com//iot/latest/apireference/API_ListThingPrincipalsV2.html)」を参照してください。

# モノからプリンシパルをデタッチする
<a name="detach-thing-principal"></a>

`DetachThingPrincipal` コマンドを使用すると、モノから証明書をデタッチできます。

```
$ aws iot detach-thing-principal \
    --thing-name "MyLightBulb" \
    --principal "arn:aws:iot:us-east-1:123456789012:cert/2e1eb273792174ec2b9bf4e9b37e6c6c692345499506002a35159767055278e8"
```

**DetachThingPrincipal** コマンドでは、出力が生成されません。

詳細については、「*AWS IoT Core API リファレンス*」の「[detach-thing-principal](https://docs.aws.amazon.com//iot/latest/apireference/API_DetachThingPrincipal.html)」を参照してください。