npm inpx cdk deploy- Two terminals opened
- Websocket-CLI installed (e.g. Websocat)
websocat <StackOutput.WebSocketUrl>in one of the terminals enter:
{"action":"whoAmI"}this should return something like: bUPgldy-FiACE_Q=
in the other terminal enter:
{"action":"sendMessage","connectionId":"<ID-FROM-ABOVE>","message":"Hello!"}If everything worked successfully you should now see your message in the first terminal.
- When you establish a websocket connection, the lambda
connectHandlerwill be executed.- This is saving the connectionId into a dynamodb table, which could be used for different purposes like broadcasting.
- When you close the websocket connection, the lambda
disconnectHandlerwill be executed.- This is removes the connectionId from a dynamodb table.
- When you have a connection open and post a message with an action property, it will route the message to the configured lamdba.
- See Diagram
First of all, Lambdas are not constantly running!
When you send a message into the opened connection API-Gateway tries to route the message to the corresponding lambda, based on the action argument.
When someone tries to send a message to a open connection, you need the use the PostToConnection-Command.
