连接和发布策略示例
对于在 AWS IoT Core 注册表中注册为事物的设备,以下策略授予权限以使用与事物名称匹配的客户端 ID 连接到 AWS IoT Core,并将设备限制为在客户端 ID 或事物名称特定的 MQTT 主题上发布。要成功建立连接,必须在 AWS IoT Core 注册表中注册事物名称,并使用附加到事物的身份或委托人对事物名称进行身份验证:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action":["iot:Publish"], "Resource": ["arn:aws:iot:us-east-1:123456789012:topic/${iot:Connection.Thing.ThingName}"] }, { "Effect": "Allow", "Action": ["iot:Connect"], "Resource": ["arn:aws:iot:us-east-1:123456789012:client/${iot:Connection.Thing.ThingName}"] } ] }
对于未在 AWS IoT Core 注册表中注册为事物的设备,以下策略授予权限以使用客户端 ID client1
连接到 AWS IoT Core,并将设备限制为在客户端 ID 特定的 MQTT 主题上发布:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action":["iot:Publish"], "Resource": ["arn:aws:iot:us-east-1:123456789012:topic/${iot:ClientId}"] }, { "Effect": "Allow", "Action": ["iot:Connect"], "Resource": ["arn:aws:iot:us-east-1:123456789012:client/client1"] } ] }