https://github.com/softprops/serverless-aws-rust-websockets
⚡🏗️ template for new aws lambda websocket serverless rust apps
https://github.com/softprops/serverless-aws-rust-websockets
aws-lambda lambda push serverless serverless-framework websockets
Last synced: about 1 year ago
JSON representation
⚡🏗️ template for new aws lambda websocket serverless rust apps
- Host: GitHub
- URL: https://github.com/softprops/serverless-aws-rust-websockets
- Owner: softprops
- License: mit
- Created: 2019-03-18T12:43:02.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-06-02T03:38:03.000Z (almost 6 years ago)
- Last Synced: 2025-03-17T12:00:01.897Z (about 1 year ago)
- Topics: aws-lambda, lambda, push, serverless, serverless-framework, websockets
- Language: Rust
- Homepage:
- Size: 176 KB
- Stars: 29
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# serverless aws websockets
exploration into Rust and [serverless websockets](https://serverless.com/framework/docs/providers/aws/events/websocket/)
## deploy
```sh
$ npm ci && npx serverless deploy
```
You can use the `wscat` command line utility to connect and communicate with your
serverless application.
```sh
$ npx wscat -c wss://{YOUR-API-ID}.execute-api.{YOUR-REGION}.amazonaws.com/dev
```
This should open up an interactive repl with which you can communicate with the server
You can send messages to the server with a json payload containing an "action" field of "send" with an optional text "message" field
```
connected (press CTRL+C to quit)
> {"action":"send"}
< {"message":"🏓 pong"}
> {"action":"send", "message":"psst"}
< {"message":"psst"}
```
## how it works
### Traditional websocket servers
A typical websocket server requires an ability to speak a binary protocol over an upgraded
http protocol connection. By its nature, that requires the operational capability to maintain a
long lived persistant connection with many connected clients.
A server with a sturdy security posture should
also provide a means of encrypting information passed across network connections. Secure websocket connections require additional handshake procedures which requires additional binary protocol extensions that you are responsible for.
### Serverless websocket applications
API Gateway replaces the need for you to write and operator traditional websocket servers. API Gateway exposing a tls (wss) websocket endpoint and manages persistent connections **for you** freeing you up to focus application specific details.
Your application need only implement functions to be invoked to specific lifecycle events called "routes". A few special routes are `$connect` `$disconnect` and `$default` which represent a new client connecting, an existing client disconnecting, and an unmapped request route respectively. You are not responsible for maintaining a network connections but you _are_ responsible
for maintaining **connection identifiers**. Managed serverless data stores like [Dynamo DB](https://aws.amazon.com/dynamodb/) make storing this trivially simple.
You can also route based on a request pattern. By default, with Serverless framework, it's expected connected clients send the server JSON payloads containing an "action" field which a handler gets routed to based on its value. This example application routes on an action called "send".
Doug Tangren (softprops) 2019