bash - BASH 中的自动化——在 AWS-IoT 中创建事物。创建后如何检索thingId?
问题描述
这是我们在 AWS 中使用 BASH 脚本创建事物的时候。它运行良好,但我想检索 thing_ID 并将其存储在变量中。
这是创建事物的 bash 代码。这是蚊子的第一次调用,mosquitto_pub --cafile root.cert --cert deviceCertAndCACert.crt --key deviceCert.key -h xxxxx.iot.us-east-2.amazonaws.com -p 8883 -q 1 -t foo/bar -I anyclientID --tls-version tlsv1.2 -m "Hello" -d
但在第一次连接中它只返回:
Client anyclientID18351 sending CONNECT
Error: The connection was lost.
创建后如何检索thing_Id?
这是代码:
openssl genrsa -out deviceCert.key 2048
openssl req -new -key deviceCert.key -out deviceCert.csr -subj "/C=CA/ST=ON/L=NY/O=SC/OU=DG/CN=EX"
openssl x509 -req -in deviceCert.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out deviceCert.crt -days 365 -sha256
cat deviceCert.crt rootCA.pem > deviceCertAndCACert.crt
wget https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem
mv VeriSign-Class\ 3-Public-Primary-Certification-Authority-G5.pem root.cert
mosquitto_pub --cafile root.cert --cert deviceCertAndCACert.crt --key deviceCert.key -h xxxxx.iot.us-east-2.amazonaws.com -p 8883 -q 1 -t foo/bar -I anyclientID --tls-version tlsv1.2 -m "Hello" -d
mosquitto_pub --cafile root.cert --cert deviceCertAndCACert.crt --key deviceCert.key -h xxxxx.iot.us-east-2.amazonaws.com -p 8883 -q 1 -t foo/bar -I anyclientID --tls-version tlsv1.2 -m "Thing $i is Working" -d
解决方案
如果您知道事物的名称,则可以在 CLI 中使用describe-thing命令。
aws iot describe-thing --thing-name ENTER_THING_NAME_HERE
回复:
{
"defaultClientId": "anyclientID",
"thingName": "THING_NAME",
"thingId": "40da2e73-c6af-406e-b415-15acae538797",
"thingArn": "arn:aws:iot:us-east-2:123456789012:thing/THING_NAME",
"thingTypeName": "LightBulb",
"attributes": {
"model": "123",
"wattage": "75"
},
"version": 1
}
推荐阅读
- javascript - 如何通过多个页面的异步获取请求将数据存储在数组中?
- sharepoint-online - 组合框选定的值不保留
- php - 使用数组数据格式化 Excel Laravel
- python - 为什么这个 SQL INSERT INTO 语句会抛出错误:TypeError: not all arguments convert during string formatting
- ios - currentContext 表示样式改变子视图控制器视图的大小
- mysql - 无法使用 java.util.UUID 从主键为二进制 (128) 的 Mysql db 检索数据
- firebase - Firebase 即时用户禁用?
- calayer - 通过 AVAssetExportSession 导出时,CABasicAnimation 不更新自定义 CALayer 属性
- scala - Scala Recursive For Comprehension 只在空列表前面添加一次,为什么?
- ios - 在 SwiftUI 表单中有多个列