步骤 1:创建 AWS IoT 策略 - AWS IoT SiteWise

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

步骤 1:创建 AWS IoT 策略

在此过程中,创建一个允许您的设备访问 AWS IoT 本教程中使用的资源的 AWS IoT 策略。

创建 AWS IoT 策略
  1. 登录到 AWS Management Console

  2. 查看支持AWSAWS IoT SiteWise 的地区。如有必要,切换到其中一个受支持的区域。

  3. 导航到 AWS IoT 控制台。如果出现 “Connect 设备” 按钮,请选择该按钮。

  4. 在左侧导航窗格中,选择安全,然后选择策略

  5. 选择创建

  6. 输入 AWS IoT 策略的名称(例如,SiteWiseTutorialDevicePolicy)。

  7. 政策文档下,选择 JSON,以 JSON 形式输入以下政策。将 regionaccount-id 替换为您的区域和账户 ID,例如 us-east-1123456789012

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iot:Connect", "Resource": "arn:aws:iot:region:account-id:client/SiteWiseTutorialDevice*" }, { "Effect": "Allow", "Action": "iot:Publish", "Resource": [ "arn:aws:iot:region:account-id:topic/$aws/things/${iot:Connection.Thing.ThingName}/shadow/update", "arn:aws:iot:region:account-id:topic/$aws/things/${iot:Connection.Thing.ThingName}/shadow/delete", "arn:aws:iot:region:account-id:topic/$aws/things/${iot:Connection.Thing.ThingName}/shadow/get" ] }, { "Effect": "Allow", "Action": "iot:Receive", "Resource": [ "arn:aws:iot:region:account-id:topic/$aws/things/${iot:Connection.Thing.ThingName}/shadow/update/accepted", "arn:aws:iot:region:account-id:topic/$aws/things/${iot:Connection.Thing.ThingName}/shadow/delete/accepted", "arn:aws:iot:region:account-id:topic/$aws/things/${iot:Connection.Thing.ThingName}/shadow/get/accepted", "arn:aws:iot:region:account-id:topic/$aws/things/${iot:Connection.Thing.ThingName}/shadow/update/rejected", "arn:aws:iot:region:account-id:topic/$aws/things/${iot:Connection.Thing.ThingName}/shadow/delete/rejected" ] }, { "Effect": "Allow", "Action": "iot:Subscribe", "Resource": [ "arn:aws:iot:region:account-id:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/shadow/update/accepted", "arn:aws:iot:region:account-id:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/shadow/delete/accepted", "arn:aws:iot:region:account-id:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/shadow/get/accepted", "arn:aws:iot:region:account-id:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/shadow/update/rejected", "arn:aws:iot:region:account-id:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/shadow/delete/rejected" ] }, { "Effect": "Allow", "Action": [ "iot:GetThingShadow", "iot:UpdateThingShadow", "iot:DeleteThingShadow" ], "Resource": "arn:aws:iot:region:account-id:thing/SiteWiseTutorialDevice*" } ] }

    此策略使您的 AWS IoT 设备能够使用 MQTT 消息建立连接并与设备影子通信。有关 MQTT 消息的更多信息,请参阅什么是 MQ TT? 。要与设备影子进行交互,您的 AWS IoT 事物会发布和接收有关以开头的主题的 MQTT 消息。$aws/things/thing-name/shadow/此策略包含一个称为 “事物” 策略变量${iot:Connection.Thing.ThingName}。此变量在每个主题中替换关联事物的名称。该iot:Connect语句限制了哪些设备可以建立连接,从而确保事物策略变量只能替换以开头的名称SiteWiseTutorialDevice

    有关更多信息,请参阅AWS IoT 开发人员指南中的事物策略变量

    注意

    此策略适用于名称以 SiteWiseTutorialDevice 开头的事物。要为您的事物使用不同的名称,您必须相应地更新策略。

  8. 选择创建