D’autres exemples de kits AWS SDK sont disponibles dans le référentiel GitHub AWS Doc SDK Examples
Utilisation de ListThings avec un kit AWS SDK ou une interface de ligne de commande
Les exemples de code suivants illustrent comment utiliser ListThings.
- CLI
-
- AWS CLI
-
Exemple 1 : pour répertorier tous les objets du registre
L’exemple
list-thingssuivant répertorie les objets (appareils) définis dans le registre AWS IoT de votre compte AWS.aws iot list-thingsSortie :
{ "things": [ { "thingName": "ThirdBulb", "thingTypeName": "LightBulb", "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/ThirdBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 2 }, { "thingName": "MyOtherLightBulb", "thingTypeName": "LightBulb", "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/MyOtherLightBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 3 }, { "thingName": "MyLightBulb", "thingTypeName": "LightBulb", "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/MyLightBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 1 }, { "thingName": "SampleIoTThing", "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/SampleIoTThing", "attributes": {}, "version": 1 } ] }Exemple 2 : pour répertorier les objets définis dotés d’un attribut spécifique
L’exemple
list-thingssuivant affiche une liste d’objets dotés d’un attribut nomméwattage.aws iot list-things \ --attribute-namewattageSortie :
{ "things": [ { "thingName": "MyLightBulb", "thingTypeName": "LightBulb", "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/MyLightBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 1 }, { "thingName": "MyOtherLightBulb", "thingTypeName": "LightBulb", "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/MyOtherLightBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 3 } ] }Pour plus d’informations, consultez Comment gérer des objets avec le registre dans le Guide du développeur AWS IoT.
-
Pour plus de détails sur l’API, consultez ListThings
dans la Référence des commandes de l’AWS CLI.
-
- Rust
-
- SDK pour Rust
-
Note
Il y en a plus sur GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS
. async fn show_things(client: &Client) -> Result<(), Error> { let resp = client.list_things().send().await?; println!("Things:"); for thing in resp.things.unwrap() { println!( " Name: {}", thing.thing_name.as_deref().unwrap_or_default() ); println!( " Type: {}", thing.thing_type_name.as_deref().unwrap_or_default() ); println!( " ARN: {}", thing.thing_arn.as_deref().unwrap_or_default() ); println!(); } println!(); Ok(()) }-
Pour plus de détails sur l’API, consultez ListThings
dans la Référence des API du kit AWS SDK pour Rust.
-