【问题标题】:Automation in BASH- Creating thing in AWS-IoT. How can I retrieve the thingId after its creation?BASH 中的自动化——在 AWS-IoT 中创建事物。创建后如何检索thingId?
【发布时间】:2020-05-05 12:59:41
【问题描述】:

这是我们在 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

【问题讨论】:

    标签: bash automation aws-cli aws-iot


    【解决方案1】:

    如果您知道事物的名称,则可以在 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
    }
    

    【讨论】:

    • 创建事物和附加证书的代码是这个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 与代理的第一个连接。不幸的是,这段代码(第一次)返回一个错误,这是 AWS 创建这个东西的时候。我无法检索所创建事物的名称。
    • 你对这件事有任何迹象吗?除了这个还有其他的吗?也许你可以列出所有的东西,然后用一些逻辑过滤掉它们
    • 在一天结束时,我不得不将我的逻辑转移到执行相同任务的 lambda(使用 NodeJS)。任务是创建事物,激活它们并为每个创建的事物返回私钥和证书。但现在我无法将这个东西附加到我在 AWS-iot 中创建的 CA 根证书。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    相关资源
    最近更新 更多