Menu
AWS IoT
Developer Guide

Managing Things with the Thing Registry

You use the AWS IoT console or the AWS CLI to interact with the registry. The following sections show how to use the CLI to work with the thing registry.

Create a thing

The following command shows how to use the AWS IoT create-thing CLI command to create a thing:

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

The create-thing API will display the name and ARN of your new thing:

Copy
{ "thingArn": "arn:aws:iot:us-east-1:803981987763:thing/MyLightBulb", "thingName": "MyLightBulb" }

List things

You can use the list-things API to list all things in your account:

Copy
$ aws iot list-things { "things": [ { "attributes": { "model": "123", "wattage": "75" }, "version": 1, "thingName": "MyLightBulb" }, { "attributes": { "numOfStates":"3" }, "version": 11, "thingName": "MyWallSwitch" } ] }

Search for things

You can use the describe-thing API to list information about a thing:

Copy
$ aws iot describe-thing --thing-name "MyLightBulb" { "version": 3, "thingName": "MyLightBulb", "defaultClientId": "MyLightBulb", "thingTypeName": "StopLight", "attributes": { "model": "123", "wattage": "75" } }

You can use the list-things API to search for all things associated with a thing type name:

Copy
$ aws iot list-things --thing-type-name "LightBulb"
Copy
{ "things": [ { "thingTypeName": "LightBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 1, "thingName": "MyRGBLight" }, { "thingTypeName": "LightBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 1, "thingName": "MySecondLightBulb" } ] }

You can use the list-things API to search for all things that have an attribute with a specific value:

Copy
$ aws iot list-things --attribute-name "wattage" --attribute-value "75"
Copy
{ "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" } ] }

Update a thing

You can use the update-thing API to update a thing:

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

The update-thing command does not produce output. You can use the describe-thing API to see the result:

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

Delete a thing

You can use the delete-thing API to delete a thing:

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

Attach a principal to a thing

A physical device must have an X.509 certificate in order to communicate with AWS IoT. You can associate the certificate on your device with the thing in the thing registry that represents your device. To attach a certificate to your thing, use the attach-thing-principal API:

Copy
$ aws iot attach-thing-principal --thing-name "MyLightBulb" --principal "arn:aws:iot:us-east-1:123456789012:cert/a0c01f5835079de0a7514643d68ef8414ab739a1e94ee4162977b02b12842847"

The attach-thing-principal command does not produce any output.

Detach a principal from a thing

You can use the detach-thing-principal API to detach a certificate from a thing:

Copy
$ aws iot detach-thing-principal --thing-name "MyLightBulb" --principal "arn:aws:iot:us-east-1:123456789012:cert/a0c01f5835079de0a7514643d68ef8414ab739a1e94ee4162977b02b12842847"

The detach-thing-principal command does not produce any output.