Skip to content

⚡🏗️ template for new aws lambda websocket serverless rust apps

License

Notifications You must be signed in to change notification settings

softprops/serverless-aws-rust-websockets

Repository files navigation

serverless aws websockets

exploration into Rust and serverless websockets

deploy

$ npm ci && npx serverless deploy

You can use the wscat command line utility to connect and communicate with your serverless application.

$ 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 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

About

⚡🏗️ template for new aws lambda websocket serverless rust apps

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages