mwalker638 / simple-golang-websockets-chat-app

This AWS SAM application provides Lambda functions written in Go, DynamoDB table, and roles to allow you to build a simple chat application based on API gateway's WebSocket-based API feature.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

simple-golang-websockets-chat-app

I was looking for a exmaple of deploying and managing a AWS Lambda based app written in Go that is deployed via AWS SAM and uses WebSockets. The closest I found was simple-websockets-chat-app, which did all of the above but in Node.js.

This repository represents a fork of simple-websockets-chat-app but with the Lambda functions written as a single Go package.

I share incase it might be useful to anyone else looking to go down this path.

There is a single golang function which handles the the logic of the simple WebSocket which uses DynamoDB for its persistent storage. A SAM template is used for ease of deployment and management.

.
├── README.md                <-- This instructions file
├── chatapp                  <-- Golang source code for websocket chatapp
└── template.yaml            <-- SAM template for Lambda Functions and DDB

Deploying to your account

AWS CLI commands

If you prefer, you can install the AWS SAM CLI and use it to package, deploy, and describe your application. Following are the commands I use:

sam build

sam deploy --guided

Testing the chat API

To test the WebSocket API, you can use wscat, an open-source command line tool.

  1. Install NPM.
  2. Install wscat:
$ npm install -g wscat
  1. On the console, connect to your published API endpoint by executing the following command:
$ wscat -c wss://{YOUR-API-ID}.execute-api.{YOUR-REGION}.amazonaws.com/{STAGE}
  1. To test the sendMessage function, send a JSON message like the following example. The Lambda function sends it back using the callback URL:
$ wscat -c wss://{YOUR-API-ID}.execute-api.{YOUR-REGION}.amazonaws.com/prod
connected (press CTRL+C to quit)
> {"message":"sendmessage", "data":"hello world"}
< hello world

License Summary

This sample code is made available under a MIT license. See the LICENSE file.

About

This AWS SAM application provides Lambda functions written in Go, DynamoDB table, and roles to allow you to build a simple chat application based on API gateway's WebSocket-based API feature.

License:MIT License


Languages

Language:Go 100.0%