This article is to bring a small example of how to use an MQTT channel using AWS services and code it in javascript, more specifically, node.js, due to the complexity, extension of the topic I will do it in parts, the articles are subject to changes and I am assuming you have a strong technical background so you can go through the article and understand it.
![]() |
| Sample diagram using an MQTT broker |
Anyhow, if you have questions, suggestions or find any inconsistency feel free to reach me to do the change.
Why I did it ?
Because I spend a lot of time searching for it on the internet and of course I found everything there but on different pieces which I had to put together, test them, adjust and after a lot of hours it worked. So maybe for the next person will be "easier" to do and if not then it will work as a precedent to how things were done, so let's start.
First we need to have an AWS account which is basically the place were our service is going to be working (you can create your account by clicking here),the product we're going to look for is called "IoT Core" and there it is the basic stuff to establish your communication channel using the protocol MQTT.In this part you'll be able to create a "thing" that will be using your service and of course you will be managing.
You can create/register your "thing" on the "manage" section by clicking on the "create" button.After you register your "thing" you'll need to have the certificate, public and private key of the device to authenticate and use the resources of the MQTT channel, this keys can be generated by AWS or you depending in case you want to have another CA than AWS, in this case we selected the certificates provided by AWS.
Now that you have your Certificate,Pair of Keys and CA Root certificate you're free to go and use the MQTT channel.
At this point, you should have your certificates in one folder ready to be used and to test that your MQTT channel is up and running i suggest using the good old CURL to perform this test.
To perform the text, we need to validate that we are able to send a message to our topic using CURL so let's try with the following line (you can copy and paste it on your terminal)
curl --tlsv1.2 --cacert root-CA.crt --cert certificate.pem.crt --key private.pem.key -X POST -d "{ \"serialNumber\": \"0000000000000000\", \"clickType\": \"SINGLE\", \"batteryVoltage\": \"2000mV\" }" "https://<my_custom_endpoint>.amazonaws.com:8443/ topics/<my_topic>?qos=1"
When you have everything ready open a terminal window, then run the CURL command and the result shall be the following
![]() |
| CMD terminal |
Once that you run it you shall be able to see your "message" on the Test section provided by AWS, which if it is the case you have already and MQTT channel open and you're able to use it, congrats!!
![]() |
| Test section under IoT Core |
On the next article we will be explaining how to use this result on a node.js code to subscribe and/or publish to an MQTT channel under an specific TOPIC.
Thank you for reading and I hope to have the ready the next article.
Luis O.





