- Websockets are helpful when you need to have two way direction between an application and client
- Use case in this example: receiving a web notification when an item is removed or put into an s3 bucket
- Very useful when making an http call that takes a while to process for example using AWS Polly or AWS translate
- Very common use case is for chat applications
- Deploy the app with the AWS SAM CLI
- Find your websocket URL in the AWS console, create a file called
config.js
atsrc/frontend/src/config.js
, and add the following:
export default {
connection: < WEBSOCKET URL HERE STARTING WITH wss: >
};
cd src/frontend/src
&&npm install
&&npm start
- Open browser console
- Add and remove items from the s3 bucket via the AWS console and see the messages in your browser console
- Can also hit the 'send message' button in the web UI to send a message and get an echoed response
- Open up the frontend on multiple browsers and/or use
wscat
in on the command line and see the messages broadcast to all clients