Mastering AWS MQTT

Use MQTTX client tool, to test AWS MQTT Broker Publish/Subscribe service.

5 min read

Learn how to configure and test your AWS MQTT Broker Publish/Subscribe service with the MQTTX client tool.

image source: link

Hello Jawans, 😎, today we will be learning about MQTT, the basics of AWS, AWS-Mqtt, MQTTX Client, and how to Publish and Subscribe to MQTT Topic. Howzzzzz the Joshhhhhhhh …???… ⭐🤩🔥

To learn about MQTT Architecture and how it works in detail read my previous tutorial: Mqtt part1

📝 In this blog we will not focus on how to set up an MQTT Broker in AWS. If you want a separate tutorial on this, please clap 👏 and comment.

1. Setting up AWS MQTT Thing

To use the AWS MQTT service, we need to:
I. First create an AWS account.
II. Look for the IOT Core option, if not available then simply use the search box.

III. Look for an Option Thing and Create a new Thing or use an existing Thing.

Creating a new AWS Thing

IV. After creating Thing go to the Security Tab and create a new Certificate or use an existing Certificate.

Creating a new Certificate

V. If you are creating a new Certificate, then Download the Keys immediately because it cannot be accessed later. If you are using an existing Certificate, then make sure that you have the keys downloaded.

Downloading keys for the new Certificate

VI. Go to the tab Policies and Create a new Policy or use an existing Policy.

Creating new Policy

VII. Once AWS Thing, Certificate, and Policy is created Attach Policy and Thing with the Certificate.

Attaching Policy to the Certificate

Attaching Thing to the Certificate


2. Setting up MQTT-X Client to Connect to AWS MQTT Broker

First, we need to download the MQTT-X Client from their official website: MQTTX Download

I. Connection:
Create a new connection by clicking the + symbol and then entering the details of the newly created AWS Thing. Give a name to this connection and also a name to the MQTT Client. In the host section choose mqtts:// and provide the endpoint of the AWS Thing. Use the Port value as 8883 and switch on SSL options.

Creating a new Connection to AWS MQTT Broker in MQTT-X Client

II. AWS Thing Endpoint
To get the endpoint value run the command on the AWS console
aws iot describe-endpoint — output json.

EndPoint for the AWS Thing

III. Adding Certificate
To add the downloaded Certificate, select Certificate type as Self signed. Add AmazonRootCA1.pem, Device Certificate.crt, and private key.key. After Adding the certificates just click to connect.

Adding Certificates to validate the connection to AWS MQTT Broker

3. Subscribing to a MQTT Topic

Once connected to the AWS MQTT Broker create a New Subscription. Enter the topic that you want to subscribe to and later use the same Topic to Publish the message.

Creating new Subscription

Entering the Topic for Subscription

4. Publishing to a MQTT Topic

After connecting to the AWS MQTT Broker and Subscribing to a Topic. We need to Publish on the same Topic and push some messages to the Topic.
Point 1: Our Created Subscription is ready.
Point 2: We need to mention the Topic name to Pulish and also the message.
Point 3: After adding Topic and Message we can publish the message using the send button.

5. AWS MQTT in Action

Since we have learned how to configure AWS Thing, how to download Certificates, get Endpoint Values, and use those values to configure the MQTT-X Client. Let’s see the AWS MQTT and MQTT-X client in action.

Below we are subscribing and publishing to the same Topic
AWS-MQTT/Topic1

AWS MQTT and MQTT-X Client in Action

6. Node-Red and MQTT-X Client Integration

Node-RED is an open-source flow-based development tool for visual programming. It is typically used for wiring together devices, APIs, and online services in a way that’s easy to understand and deploy.
website: Node-RED (nodered.org)
Below we can see that Node-Red is publishing a message to the Topic AWS-MQTT/Topic1 and the MQTT-X Client is subscribing to the same topic. They both are sharing the message using the AWS MQTT Broker

Node-Red and MQTT-X Client communicating using AWS MQTT Broker.

If you want to learn how to configure Node-Red and integrate Node-Red with AWS MQTT then please clap 👏 and leave a comment.

If you find this tutorial helpful, then don’t forget to follow me.

Join the newsletter

Be the first to read our articles.

Create a free website with Framer, the website builder loved by startups, designers and agencies.