Need help with aws-iot-chat-example?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

491 Stars 110 Forks Apache License 2.0 126 Commits 5 Opened issues


💬 Chat application using AWS IoT platform via MQTT over the WebSocket protocol

Services available


Need anything else?

Contributors list

AWS IoT Chat Application

tested with jest GitHub stars GitHub license Demo Online

This is a React application demonstrating how to use the AWS IoT platform via MQTT over the WebSocket protocol to build a live chat application. The sample application serves as a starting point for users to build serverless projects with Amazon Cognito, AWS Lambda and Amazon DynamoDB. The project showcases the solution to common user questions such as how to authenticate IoT devices with Amazon Cognito.

Table of Contents


  • Register user
  • Login / Logout
  • Create room
  • Join room
  • Real-time chat
  • Unread message indicators

AWS Services Showcased




Please note that this project has only been tested on macOS. Windows users may need to update some of the scripts. Pull requests are welcome to add Windows support.

  • Install and configure the AWS Command Line Interface
    • Ensure that the aws cli region is the same as what you define in
    • Please configure your
      format to be
      . Instructions
  • jq to process command-line JSON.
  • npm the node package manager
  1. Clone the repository
$ git clone
  1. Deploy the backend

If you would like to enable login with Facebook and/or Google, please follow the Social Logins guide.

$ cd api
$ sudo npm install -g serverless
$ npm install
$ serverless deploy

The Serverless Framework is a tool for deploying serverless architectures. The stack including Lambda functions and CloudFormation resources are defined in


After deploying the serverless application, two scripts are invoked by means of a lifecycle hook. The first,

is used to attach a Lambda function to the PreSignUp trigger on the Cognito User Pool.

The second script in

uses the AWS CLI to query the Cloudformation template output variables and stores them in the file
. This auto-generated file is then imported by
and used within the client side application.
  1. Run the frontend client
$ cd ../client
$ npm install
$ npm start

It is important to run the setup script so that the client knows the destination of the AWS IoT endpoint, API Gateway endpoint and other coniguration variables generated by

serverless deploy
  1. Open
    and try it out!


To tear down the stack, use the command

serverless remove

Application Walkthrough

Try the app on the Demo website

  1. Register Page

Register a user using Amazon Cognito User Pools. You can use user pools to add user registration and sign-in features to your apps.


  1. Login page

Login a user using Amazon Cognito User Pools.

Alternatively, you can use Amazon Cognito Federated Identities to create unique identities for your users and federate them with identity providers such as Facebook and Google.


  1. Rooms List

Displays the list of available rooms to join. If you are subscribed to a room, there will be an icon indication. The number of unread messages to subscribed rooms is also displayed. Lastly, on this screen you can create a room. The application will generate an appropriate topic name to publish on if your room name contains illegal characters.

All HTTP API endpoints are AWS Lambda functions invoked through Amazon API Gateway.

Rooms list

  1. Room

This is the main chat page where the real-time messaging is displayed. You will still be subscribed to other rooms as indicated by the unread message counters that increment when a message is received. Sending a message will dispatch a message to AWS IoT which in turn is responsible for fanning out the messages to all the subscribers of the room.

Architecture Walkthrough


Redux Flows

Auth Flow Messaging Flow Rooms Screen Flow


To deploy the backend, this project uses the Serverless Framework which is backed by AWS CloudFormation. In the

file, functions, events, resources and services are defined which Serverless uses to deploy the appropriate Lambda functions, API Gateway services and additional CloudFormation resources.

IoT Topics

MQTT (Message Queue Telemetry Transport) protocol uses a hierarchical structure to describe the topic space. Multi-level

wildcards and single-level
wildcards can be used in addition to topic level separators

In this application, topics are subscribed to using the form:


This matches topics such as:


Note the last example topic because this is the topic that users will publish to.


Based on the MQTT specification, a receiving client does not know who published the message without either including the message author in the message payload itself or by encoding the message author in the message topic.

This application opted for the second option by appending the cognito identity id to the end of the publishing topic. To prevent users from publishing to other user's topics, the AWS Lambda function

creates a dynamic IoT policy that allows only that one identity to publish messages to their unique topic.

Other guides


In both the

npm run test
can be used to run unit tests using jest

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.