API Gateway WebSocket API
- For real-time and stateful application in API Gateway
- Client connect to server
- Connecting using
wss://[unique-id].execute-api.[region].amazonaws.com/[stage-name]
- We invoke the
onConnect
lambda function upon connection and the lambda function can storeconnectionId
to DynamoDB for example
- Connecting using
- Client to server
- When client sending messages (frames) it invoke a
sendMessage
lambda function witht he sameconnectionId
- When client sending messages (frames) it invoke a
- Server returns client
- Server talk back to client using a Connection URL callback
- Lambda function can then do a POST to the URL callback to connect back to the client
wss://[uniqueid].execute-api.[region].amazonaws.com/[stage]/@connections/[connectionId]
- Server talk back to client using a Connection URL callback
- Connection URL
- Has the format
wss://[uniqueid].execute-api.[region].amazonaws.com/[stage]/@connections/[connectionId]
POST
: send message from Server to ClientGET
: get the latest connection status of the connected WS ClientDELETE
: Disconnect the client from WS connection
- Has the format
Routing
- Incoming JSON messages are routed to different back end
- If ther is no rount, it sends to
$default
- Specify a route selection to select the field on JSON to act as route
- For example,
$request.body.action
- The result is avaluated against route keys available in your API Gateway
- The route then connected to backend you've setup through API gateway
- For example,