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

Viewed 97

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?

1 Answers

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.

Related