WebSockets
Overview
Real-time updates (game moves, chat, dashboard refreshes) use API Gateway WebSockets plus an SQS-backed broadcaster.
Connection flow
- Client opens WebSocket to the stage API (
wss://…/{stage}). $connect—connectHandlerstores connection id underwsConnections.subscribe—authHandlervalidates the user and subscribes the connection to topics (e.g. user id, game id).$disconnect—disconnectHandlerremoves the connection record.
Broadcasting
lib/wsBroadcast.ts enqueues messages to WEBSOCKET_SQS. The messageHandler Lambda reads the queue and posts to active connections via API Gateway Management API.
Record type
pk: wsConnections
sk: <connectionId>
Configuration
Per-stage WebSocket domain and SQS URL are in serverless.yml (WEBSOCKET_DOMAIN, WEBSOCKET_SQS, WEBSOCKET_STAGE).