【问题标题】:How to get user's spesific "Things" from AWS IoT service and not all the Things in the system如何从 AWS IoT 服务获取用户的特定“事物”,而不是系统中的所有事物
【发布时间】:2022-01-13 05:43:07
【问题描述】:

我开发了一个 android 应用,我只想获取与特定登录用户相关的 事物 目前我得到了系统中的所有事物,我想避免从 AWS 检索所有事物。

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

这是我用来获取所有事物的代码,有什么建议吗?

【问题讨论】:

    标签: android amazon-web-services mobile amazon-cognito aws-iot


    【解决方案1】:

    您首先需要一种将用户与她的设备相关联的方法。一个简单的选项是添加一个ownerThing Attribute。属性是我们可以在 Things 上设置的键值对。

    一旦我们定义了事物的所有者,我们就可以使用 listThings 的可选 attributeNameattributeValue 输入来按所有者过滤事物:

    # 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}]}
    

    请注意,这种方法只是过滤事物。它不限制访问。

    【讨论】:

    • 我知道这个选项,但是如果每个应用程序都可以正确获取所有设备,它会导致安全问题吗?可能有更正确的方法来做到这一点......
    • 对。该问题没有提及访问控制要求或说出您已经尝试过的内容,只是“避免检索所有事物”。答案的最后一句话警告它不涉及授权。请参阅this related question 了解可行的方法。
    • 感谢您的回复,根据“此相关问题”链接中所写的内容,我了解 lambda 将为在 lambda 之后立即登录的用户创建并附加 IoT 策略根据“attributeName”过滤所有设备我有两个问题:1.这是安全的唯一方法(使用lambda)吗?移动 SDK 可以这样做吗? 2. 我对无服务器函数的概念不熟悉,您能否向我推荐一个链接,该链接描述了如何在 AWS 中创建 lambda 以创建“IoT 策略”
    • 很高兴为您提供帮助。 (1) 使用 AWS,做任何事情永远不会只有一种方法......但如果安全性很重要,您应该避免使用移动 SDK 创建权限。永远不要相信客户。 (2)this aws doc 有 lambda IoT 策略逻辑示例。 lambda 的工作是查找用户的设备并返回特定于设备的策略。创建一个 lambda is easy,提供大量在线帮助。
    • 好的,非常感谢。
    猜你喜欢
    • 2020-08-03
    • 2019-01-27
    • 2016-10-01
    • 2020-08-02
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多