简体   繁体   中英

How to get user's spesific "Things" from AWS IoT service and not all the Things in the system

I develop an android app and I want to get only Things that related to spesific logged-in user currently I get all the Things in the system and I want to avoid the retrieve all the Things from AWS.

val awsIotClient = AWSIotClient(AWSMobileClient.getInstance())
awsIotClient.setRegion(Region.getRegion(Regions.US_EAST_2))
val userListThings = awsIotClient.listThings(ListThingsRequest())

this is the code i use to get all the Things , any suggestion?

You first need a way to associate a user with her devices. A simple option is to add an owner Thing Attribute . Attributes are key-value pairs we can set on Things.

Once we define the Thing owners, we can filter Things by owner with the optional attributeName and attributeValue inputs to listThings :

# python, but the android API has the same method signature
iot.list_things(attributeName="owner", attributeValue="me")
{'things': [{'thingName': 'temp1',
   'thingArn': 'arn:aws:iot:us-east-1:xxxxxxxxxxxx:thing/temp1',
   'attributes': {'owner': 'me'},
   'version': 1}]}

Note that this approach is just filtering the Things. It does not restrict access.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM