Closed olgeorge closed 7 years ago
I've found the problem. The publish
method expects a string, not an object. The following line fixes it:
device.publish('test-topic', '{ "test": "test" }')
I'm still leaving this issue open as a suggestion to add proper input validation and error messages inside the SDK. Afaik the client would disconnect when an unauthorized publish action is attempted, which adds confusion to finding the the source of the bug.
Hi @olgeorge , Thanks for your interest in aws-iot-device-sdk-js. It is good to see your problem was resolved. We will take this in our backlog.
@olgeorge Thanks for your report. I know it's been a long time; how were you able to debug this? Just by CloudWatch IoT logs? I think I experienced something similar. The client showed no signs of disconnecting, but I'm not printing anything in a disconnect handler, either.
I logged the connect, close, and reconnect events. Incorrect permissions turns into a reconnect loop. Very unforgiving.
I am using Cognito identity pool together with Cognito user pool to authenticate my users. Both policies attached to the identity pool as well as each identity allow broad connect, subscribe, receive and publish. I'm able to connect to IoT with authenticated identities as well as subscribe to a topic and receive messages on it (published by AWS console). Moreover, I'm able to successfully use fine-grained permissions by using
${cognito-identity.amazonaws.com:sub}
inside the policy attached to the cognito identity, and they get replaced by the identityId with the formateu-west-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
(not shown in this code sample), so I'm pretty sure I'm doing things the right way with authentication and authorization.However, after I call device.publish(topic, message) the client disconnects. The permissions are as broad as possible, they are the same for both policies for subscribe and publish. One works but the other doesn't. Please help!
IAM role attached to the identity pool:
MyPolicy attached to federated identities:
CloudWatch logs that clearly show the successful connect, subscribe and the disconnect that follows
Here's the Javascript code: