Comment gérer des objets avec le registre - AWS IoT Core

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

Comment gérer des objets avec le registre

Vous utilisez la AWS IoT console, AWS IoT l'API ou le AWS CLI pour interagir avec le registre. Les sections suivantes montrent comment utiliser l'interface de ligne de commande pour qu'elle fonctionne avec le registre.

Lorsque vous nommez vos objets objets :
  • N'utilisez pas d'informations personnellement identifiables dans le nom de votre objet. Le nom de l'objet peut apparaître dans les communications et les rapports non chiffrés.

Créer un objet

La commande suivante montre comment utiliser la AWS IoT CreateThing commande de la CLI pour créer un objet. Vous ne pouvez pas changer le nom d'un objet une fois qu’il est créé. Pour modifier le nom d'un objet, créez-en un nouveau, donnez-lui le nouveau nom, puis supprimez l'ancien.

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

La commande CreateThing affiche le nom et l’Amazon Resource Name (ARN) de votre nouvel objet :

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

Nous vous déconseillons d'utiliser des informations personnelles identifiables dans le nom de vos objets.

Pour plus d'informations, consultez create-thing dans la AWS CLI Référence des commandes.

Liste des objets

Vous pouvez utiliser la commande ListThings pour répertorier tous les objets présents dans votre compte :

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

Vous pouvez utiliser ListThings la commande pour chercher tous les objets d’un type d’objet specifique :

$ 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" } ] }

Vous pouvez utiliser la ListThings commande pour rechercher tous les objets qui ont un attribut avec une valeur spécifique : Cette commande recherche jusqu'à trois attributs.

$ 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" } ] }

Pour plus d'informations, veuillez consulter list-objects dans la AWS CLI Référence des commandes .

Décrivez des objets

Pour afficher des informations sur un objet, vous pouvez utiliser la commande 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" } }

Pour plus d'informations, consultez describe-thing dans le manuel de référence des AWS CLI commandes.

Mettre à jour un objet

Vous pouvez utiliser la commande UpdateThing pour mettre à jour un objet : Cette commande met à jour uniquement les attributs de l'objet. Vous ne pouvez pas changer le nom d'un objet. Pour modifier le nom d'un objet, créez-en un nouveau, donnez-lui le nouveau nom, puis supprimez l'ancien.

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

La commande UpdateThing ne génère pas de sortie. Vous pouvez voir le résultat à l'aide de la commande DescribeThing :

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

Pour plus d'informations, consultez update-thing dans la AWS CLI Référence de commande.

Supprimer un objet

Vous pouvez utiliser la commande DeleteThing pour supprimer un objet :

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

Cette commande renvoie un message de succès de l'opération sans erreur si la suppression a été réussie ou que vous spécifiez un objet qui n'existe pas.

Pour plus d'informations, veuillez consulter delete-thing dans la AWS CLI Référence des commandes.

Attacher un mandataire à un objet

Un périphérique physique doit disposer d'un certificat X.509 pour communiquer avec AWS IoT. Vous pouvez associer le certificat de votre appareil à l'objet dans le registre qui représente votre appareil. Pour attacher un certificat à votre objet, utilisez la commande AttachThingPrincipal :

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

La commande AttachThingPrincipal ne génère pas de sortie.

Pour plus d'informations, consultez attach-thing-principal dans le manuel Command Reference. AWS CLI

Détacher un mandataire d'un objet

Vous pouvez utiliser la commande DetachThingPrincipal pour détacher un certificat d'un objet :

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

La DetachThingPrincipal commande ne génère pas de sortie.

Pour plus d'informations, consultez detach-thing-principal dans le manuel Command Reference. AWS CLI