`aws iot-data` command and AWS reserved topics ($)

386 Views Asked by At

I'm newbie in AWS IoT and now try to play around with existing resources to understand the main concept. I faced with an odd behaviour while using aws iot-data command trying to publish data into one of AWS reserved topics. Let's say I want to update named Shadow called stubShadow of some stub thing (I'm using Test tab in the AWS IoT Dashboard):

 aws iot-data update-thing-shadow --thing-name stub --shadow-name stubShadow \
    --cli-binary-format raw-in-base64-out \
    --payload '{"state":{"desired":{"ColorRGB":[0,11,11]}},"clientToken":"21b21b21-bfd2-4279-8c65-e2f697ff4fab"}' /dev/stdout

and it works pretty well, I can observe $aws/things/stub/shadow/name/stubShadow/update/accepted topic for updates.

Now I want to publish a message using topic argument. Here is an example:

aws iot-data publish --topic "$aws/things/stub/shadow/name/stubShadow/update" \
    --cli-binary-format raw-in-base64-out \
    --payload '{"state":{"reported":{"ColorRGB":[0,11,11]}},"clientToken":"21b21b21-bfd2-4279-8c65-e2f697ff4fab"}'

and nothing happens... I wonder what's wrong with this command with sending direct message to a AWS Service topic? Am I miss something? Because for regular (manually created) topics it works well.

2

There are 2 best solutions below

2
On

As the document says,

payload is the base64 encoded representation of stringify json message

{"state":{"reported":{"ColorRGB":[0,11,11]}}}

console.log(btoa(JSON.stringify({"state":{"reported":{"ColorRGB":[0,11,11]}}})))

payload : eyJzdGF0ZSI6eyJyZXBvcnRlZCI6eyJDb2xvclJHQiI6WzAsMTEsMTFdfX19

aws iot-data publish --topic "$aws/things/stub/shadow/name/stubShadow/update" --payload 'eyJzdGF0ZSI6eyJyZXBvcnRlZCI6eyJDb2xvclJHQiI6WzAsMTEsMTFdfX19'

0
On

When Using CLI, If you publish message, it wont reflect in shadow document. While when you give command Update Shadow- you can see the change in shadow.

This we recently observed while using MQTT Test client of AWS. Just open AWS IOT Core console and go to test client and subscribe to the topic that you are publishing.

You will observe Publish message is coming