本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
DeviceShadowEnrich 活动
一个deviceShadowEnrich
活动添加了来自Amazon IoT向消息提供Device Shadow 服务。例如,给定以下消息:
{ "temp": 50, "hum": 40, "device": { "thingName": "my-thing" } }
和以下 deviceShadowEnrich
活动:
{ "deviceShadowEnrich": { "name": "MyDeviceShadowEnrichActivity", "attribute": "shadow", "thingName": "device.thingName", "roleArn": "arn:aws:iam::<your-account-number>:role:MyEnrichRole", "next": "MyDatastoreActivity" } }
结果是一条类似于以下示例的消息。
{ "temp": 50, "hum": 40, "device": { "thingName": "my-thing" }, "shadow": { "state": { "desired": { "attributeX": valueX, ... }, "reported": { "attributeX": valueX, ... }, "delta": { "attributeX": valueX, ... } }, "metadata": { "desired": { "attribute1": { "timestamp": timestamp }, ... }, "reported": ": { "attribute1": { "timestamp": timestamp }, ... } }, "timestamp": timestamp, "clientToken": "token", "version": version } }
您必须在活动定义的 roleArn
字段中指定已附加适当权限的角色。该角色必须具有如下所示的权限策略。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iot:GetThingShadow" ], "Resource": [ "arn:aws:iot:<region>:<account-id>:thing/<thing-name>" ] } ] }
和类似如下的信任策略:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Principal": { "Service": "iotanalytics.amazonaws.com" }, "Action": [ "sts:AssumeRole" ] } ] }