node.js - 无法订阅动态主题。使用 aws-iot-device-sdk
问题描述
当我订阅连接影子的动态主题时。我无法建立连接设备。没有订阅它已连接但无法接收消息有效负载。
代码
this.thingShadows = new awsiot.thingShadow({
keyPath: keyPath,
certPath: certPath,
caPath: caPath,
clientId: clientId, //"sdk-nodejs-" + clientId,
host: host,
debug: true,
});
this.thingShadows.subscribe(clientId + "/*");
政策
{
"Effect": "Allow",
"Action": [
"iot:Connect"
],
"Resource": [
"arn:aws:iot:ap-south-1:453533943651:client/${iot:Connection.Thing.ThingName}"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Publish"
],
"Resource": [
"arn:aws:iot:us-south-1:453533943651:topic/${iot:Connection.Thing.ThingName}/*"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Subscribe"
],
"Resource": [
"arn:aws:iot:us-south-1:453533943651:topicfilter/${iot:Connection.Thing.ThingName}/*"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Receive"
],
"Resource": [
"arn:aws:iot:ap-south-1:453533943651:topic/${iot:Connection.Thing.ThingName}/*"
]
}
日志/输出
error 错误:在 processTicksAndRejections (internal/process/task_queues.js:75:11) 处的 onclosenexttick (/Users/murtuzanalawala/Node/RiooNode/node_modules/end-of-stream/index.js:54:86) 过早关闭连接丢失- 将在 128 秒内尝试重新连接...关闭重新连接/重新注册离线连接
提前感谢您的好建议。
解决方案
是的,您无法订阅动态主题,您必须将策略“arn:aws:iot:ap-south-1:453533943651:topic/${iot:Connection.Thing.ThingName}/*”更改为 *..允许所有设备。然后您可以订阅.topic/${iot:Connection.Thing.ThingName} 这表示事物名称应该位于主题的末尾。更改以允许您订阅所有内容。
推荐阅读
- python - 当我运行删除数据帧时,PySpark 没有释放内存
- google-chrome - 如何从浏览器中删除 istartsurf
- r - 无法使用池包断开闪亮应用程序中的连接
- assembly - 为什么新行不打印?
- java - 如何使用超类为Android中的所有活动设置音量?
- c++ - 如何为这个球体添加纹理?
- javascript - 谷歌云功能 onCreate 不写入数据库
- javascript - 使用 eval 或 domsanitizer 执行自定义用户脚本的 Javascript
- linux - curl:(56)OpenSSL SSL_read:SSL_ERROR_SYSCALL,errno 104
- amazon-web-services - 通过 AWS 更新代码管道期间的验证错误