This project implements a serverless chat application using AWS IoT Core. It is showcasing a real-time communication between connected clients. Additionally, it provides the infrastructure to persist and retrieve chat messages.
- Utilizes AWS CDK for infrastructure as code
- Implements serverless architecture using AWS Lambda, IoT Core & DynamoDB
- Provides real-time messaging capabilities
- Includes a simple client-side web interface for demonstration
- Node.js (v20 or later)
- AWS CLI configured with appropriate permissions
- AWS CDK installed (
npm install -g aws-cdk
)
Note: the project uses CDK constructs from IoT Core alpha modules, meaning that they are still considered experimental and under active development. Please be aware that breaking changes might happen in the future. I will keep the codebase up to date, and in the meantime feel free to consult the CDK docs of aws-iot-alpha and aws-iot-actions-alpha for details.
- Clone the repository:
git clone https://github.com/imflamboyant/serverless-aws-chat.git
- Navigate to the project directory:
cd serverless-aws-chat/chat-iot-core
- Install dependencies:
npm install
- Build the project:
npm run build
- Deploy the stack to your AWS account:
npx cdk deploy
Note the outputs from the CDK deployment, specifically the API Gateway endpoint.
- Get the IoT Core regional endpoint by running:
aws iot describe-endpoint
Make sure the region is set to the region you are deploying to. Also, you can find your endpoint by navigating to IoT Core > MQTT test client in the AWS Console.
- Then, to make the authorizer actually work, it has to be specified as a query parameter. An example URL is:
'wss://xyz.iot.{region}.amazonaws.com/mqtt?x-amz-customauthorizer-name=ServerlessChatIoTAuthorizer'
**Note: ** ServerlessChatIoTAuthorizer
is the name of the authorizer given in the CDK code.
- Update the client-side application
client/index.html
with the necessary endpoints obtained above.
After deployment, you can test the chat application by:
- Opening multiple instances of
client/index.html
file in a web browser- each client gets a randomly generated username
- Sending messages from different clients
- Observing real-time message updates in the client application
To avoid incurring future charges, remember to destroy the resources when you're done:
npx cdk destroy