The Device Shadow service uses reserved MQTT topics to enable devices and apps to get, update, or delete the state information for a device (shadow).
Publishing and subscribing on shadow topics requires topic-based authorization. AWS IoT reserves the right to add new topics to the existing topic structure. For this reason, we recommend that you avoid wild card subscriptions to shadow topics. For example, avoid subscribing to topic filters like $aws/things/thingName/shadow/#
because the number of topics that match this topic filter might increase as AWS IoT introduces new shadow topics. For examples of the messages published on these topics see Interacting with shadows.
Shadows can be named or unnamed (classic). The topics used by each differ only in the topic prefix. This table shows the topic prefix used by each shadow type.
ShadowTopicPrefix
value Shadow type $aws/things/thingName
/shadow
Unnamed (classic) shadow $aws/things/thingName
/shadow/name/shadowName
Named shadow
To create a complete topic, select the
for the type of shadow to which you want to refer, replace ShadowTopicPrefix
, and thingName
if applicable, with their corresponding values, and then append that with the topic stub as shown in the following sections.shadowName
The following are the MQTT topics used for interacting with shadows.
/getPublish an empty message to this topic to get the device's shadow:
ShadowTopicPrefix
/get
AWS IoT responds by publishing to either /get/accepted or /get/rejected.
Example policyThe following is an example of the required policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Publish"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topic/$aws/things/thingName
/shadow/get"
]
}
]
}
AWS IoT publishes a response shadow document to this topic when returning the device's shadow:
ShadowTopicPrefix
/get/accepted
For more information, see Response state documents.
Example policyThe following is an example of the required policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Subscribe"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topicfilter/$aws/things/thingName
/shadow/get/accepted"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Receive"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topic/$aws/things/thingName
/shadow/get/accepted"
]
}
]
}
AWS IoT publishes an error response document to this topic when it can't return the device's shadow:
ShadowTopicPrefix
/get/rejected
For more information, see Error response document.
Example policyThe following is an example of the required policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Subscribe"
],
"Resource": [
"arn:aws:iot:region
:111122223333
:topicfilter/$aws/things/thingName
/shadow/get/rejected"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Receive"
],
"Resource": [
"arn:aws:iot:region
:111122223333
:topic/$aws/things/thingName
/shadow/get/rejected"
]
}
]
}
Publish a request state document to this topic to update the device's shadow:
ShadowTopicPrefix
/update
The message body contains a partial request state document.
A client attempting to update the state of a device would send a JSON request state document with the desired
property such as this:
{
"state": {
"desired": {
"color": "red",
"power": "on"
}
}
}
A device updating its shadow would send a JSON request state document with the reported
property, such as this:
{
"state": {
"reported": {
"color": "red",
"power": "on"
}
}
}
AWS IoT responds by publishing to either /update/accepted or /update/rejected.
Example policyThe following is an example of the required policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Publish"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topic/$aws/things/thingName
/shadow/update"
]
}
]
}
AWS IoT publishes a response state document to this topic when it accepts a change for the device's shadow, and the response state document contains different values for desired
and reported
states:
ShadowTopicPrefix
/update/delta
The message buffer contains a /delta response state document.
Message body detailsA message published on update/delta
includes only the desired attributes that differ between the desired
and reported
sections. It contains all of these attributes, regardless of whether these attributes were contained in the current update message or were already stored in AWS IoT. Attributes that do not differ between the desired
and reported
sections are not included.
If an attribute is in the reported
section but has no equivalent in the desired
section, it is not included.
If an attribute is in the desired
section but has no equivalent in the reported
section, it is included.
If an attribute is deleted from the reported
section but still exists in the desired
section, it is included.
The following is an example of the required policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Subscribe"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topicfilter/$aws/things/thingName
/shadow/update/delta"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Receive"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topic/$aws/things/thingName
/shadow/update/delta"
]
}
]
}
AWS IoT publishes a response state document to this topic when it accepts a change for the device's shadow:
ShadowTopicPrefix
/update/accepted
The message buffer contains a /accepted response state document.
Example policyThe following is an example of the required policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Subscribe"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topicfilter/$aws/things/thingName
/shadow/update/accepted"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Receive"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topic/$aws/things/thingName
/shadow/update/accepted"
]
}
]
}
AWS IoT publishes a state document to this topic whenever an update to the shadow is successfully performed:
ShadowTopicPrefix
/update/documents
The message body contains a /documents response state document.
Example policyThe following is an example of the required policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Subscribe"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topicfilter/$aws/things/thingName
/shadow/update/documents"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Receive"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topic/$aws/things/thingName
/shadow/update/documents"
]
}
]
}
AWS IoT publishes an error response document to this topic when it rejects a change for the device's shadow:
ShadowTopicPrefix
/update/rejected
The message body contains an Error response document.
Example policyThe following is an example of the required policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Subscribe"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topicfilter/$aws/things/thingName
/shadow/update/rejected"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Receive"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topic/$aws/things/thingName
/shadow/update/rejected"
]
}
]
}
To delete a device's shadow, publish an empty message to the delete topic:
ShadowTopicPrefix
/delete
The content of the message is ignored.
Note that deleting a shadow does not reset its version number to 0.
AWS IoT responds by publishing to either /delete/accepted or /delete/rejected.
Example policyThe following is an example of the required policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Publish"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topic/$aws/things/thingName
/shadow/delete"
]
}
]
}
AWS IoT publishes a message to this topic when a device's shadow is deleted:
ShadowTopicPrefix
/delete/accepted
Example policy
The following is an example of the required policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Subscribe"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topicfilter/$aws/things/thingName
/shadow/delete/accepted"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Receive"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topic/$aws/things/thingName
/shadow/delete/accepted"
]
}
]
}
AWS IoT publishes an error response document to this topic when it can't delete the device's shadow:
ShadowTopicPrefix
/delete/rejected
The message body contains an Error response document.
Example policyThe following is an example of the required policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Subscribe"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topicfilter/$aws/things/thingName
/shadow/delete/rejected"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Receive"
],
"Resource": [
"arn:aws:iot:us-east-1
:111122223333
:topic/$aws/things/thingName
/shadow/delete/rejected"
]
}
]
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4