xHasKx / luamqtt

luamqtt - Pure-lua MQTT v3.1.1 and v5.0 client
https://xhaskx.github.io/luamqtt/
MIT License
154 stars 41 forks source link

Was it tested with AWS Iot? #29

Closed mapo-job closed 2 years ago

mapo-job commented 3 years ago

label:Question

Hi, I tried the simple client with TLS enable with correct credential information but it does not work. I'm new to lua so not sure how to troubleshoot. I have the nodejs example working but the lua script does not connect. The original lua script is working.

Result:

# lua simple.lua
created MQTT client     mqtt.client{id="lua-simple-client"}
running ioloop for it
done, ioloop is stopped

Code change:

        uri = "abcdef.123.iot.us-east-1.amazonaws.com",
        id = "lua-simple-client",
        secure = {
                mode = "client",
                protocol = "tlsv1_2",
                verify = "peer",
                options = "all",
                cafile="/lua/root-CA.pem",
                certificate="/lua/Device.cert.pem",
                key="/lua/Device.private.key"
        },
        version= mqtt.v311,
xHasKx commented 3 years ago

Yes, it's tested with AWS IoT and working.

But there should be a tricky setup in your AWS Console. In short - you should create a policy with proper actions allowed and attach that policy and thing to your certificate. If you need a step-by-step guide - see here: https://flespi.com/kb/flespi-to-aws (until the "Flespi AWS stream configuration" step). After doing the steps described in that article you will get an MQTT broker at your uri = "abcdef.123.iot.us-east-1.amazonaws.com", which can accept connection from any MQTT client, like luamqtt.

Your secure={...} table in your Lua code is correct except that "cafile" is usually "root-CA.crt", not "root-CA.pem", but you should adjust it according to your file names.

mapo-job commented 3 years ago

Just starting with Iot, thanks for the clarification. The demo has a default policy on topic "topic_1" and resource client/sdk-nodejs-. Just added "arn:aws:iot:us-east-1:############:client/lua-" solve the problem.

Thanks

Tieske commented 2 years ago

can this be closed?