简体   繁体   English

Android 中的 AWS IoT Policy 不适用于自定义主题

[英]AWS IoT Policyin Android doesnt work with custom topic

I am using AWS android SDK to connect to AWS IoT.我正在使用 AWS android SDK 连接到 AWS IoT。 The following policy allow my app to successfully connect to AWS IoT except when i make this change以下策略允许我的应用程序成功连接到 AWS IoT,除非我进行此更改

"Resource": "arn:aws:iot:us-west-2:1234567890xxx:topic/topic1" I have tried almost every possible custom option but the policy works only for "*" wild card that means "any resource and/or any topics". "Resource": "arn:aws:iot:us-west-2:1234567890xxx:topic/topic1" 我已经尝试了几乎所有可能的自定义选项,但该策略仅适用于“*”通配符,这意味着“任何资源和/或任何主题”。

Working example successfully connects android app to AWS IoT工作示例成功将 android 应用程序连接到 AWS IoT

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "iot:Connect",
             "Resource": "arn:aws:iot:us-west-2:1234567890xxx:client/mobile-client-master"
        },
        {
            "Effect": "Allow",
            "Action": [
            "iot:Publish",
            "iot:Subscribe",
            "iot:Receive"
            ],
            "Resource": "*" 
        }
     ]
}

This Json script fails to connect the android app to AWS IoT此 Json 脚本无法将 android 应用程序连接到 AWS IoT

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "iot:Connect",
             "Resource": "arn:aws:iot:us-west-2:1234567890xxx:client/mobile-client-master"
        },
        {
            "Effect": "Allow",
            "Action": [
            "iot:Publish",
            "iot:Subscribe",
            "iot:Receive"
            ],
            "Resource": "arn:aws:iot:us-west-2:1234567890xxx:topic/topic1" 
        }
     ]
}

I have tried almost every possible custom option but the policy works only for "*" wild card that means "any resource and/or any topics".我已经尝试了几乎所有可能的自定义选项,但该策略仅适用于“*”通配符,即“任何资源和/或任何主题”。

The reason is Subscribe needs topicfilter Resource and not topic原因是 Subscribe 需要topicfilter资源而不是 topic

Here's an Example:这是一个例子:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "iot:Connect"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "iot:Publish",
        "iot:Receive"
      ],
      "Resource": [
        "arn:aws:iot:us-east-1:xxx:topic/$aws/certificates/create/*",
        "arn:aws:iot:us-east-1:xxx:topic/$aws/provisioning-templates/test/provision/*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "iot:Subscribe"
      ],
      "Resource": [
        "arn:aws:iot:us-east-1:xxx:topicfilter/$aws/certificates/create/*",
        "arn:aws:iot:us-east-1:xxx:topicfilter/$aws/provisioning-templates/test/provision/*"
      ]
    }
  ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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