User connects to API Gateway with some payload, Apigateway routing the request to different Lambda functions:
There are some special routes defined for websockets,
WebSocket API provides two URLs: WebSocket URL and Connection URL.
WebSocket URL:
Connection URL:
Connection id will be stored in DynamoDB table, a lambda function will read from it.
Connection URL supports the following operations:
Here is an example of how to react to WebSocket events using Serverless Framework:
ConnectHandler:
handler: src/websocket/connect.handler
events:
- websocket:
route: $connect
DisconnectHandler:
handler: src/websocket/disconnect.handler
events:
- websocket:
route: $disconnect
npm install wscat -g
wscat -c wss://52zeaf29d.exeute-api.eu-central-1.amazonaws.com/dev
[AWS] WebSockets with API Gateway
原文:https://www.cnblogs.com/Answer1215/p/14782429.html