API Gateway Chat
API Gateway creation Websocket
Announcing WebSocket APIs in Amazon API Gateway:
Create a new WebSocket API
In the API Gateway console, choose Create API, New API.
Under Choose the protocol, choose WebSocket.
For API name, enter My Chat API.
For Route Selection Expression, enter $request.body.action.
Enter a description if you’d like and click Create API.
Websocket: paths and stage
System paths
Connect:
Connect Nodejs script github
Integration Request Configuration
Provide information about the target backend that this route will call and whether the incoming payload should be modified.
Disconnect
Disonnect Nodejs script github
Custom paths
When lambda need to execute API:
//ApiGatewayManagementApi makes a POST
// post https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ApiGatewayManagementApi.html#postToConnection-property
apiGatewayManagementApi.postToConnection(paramsToSendToChatGroup, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
you need to give permissoin to lambda to execute ApiGatewayManagementApi and just work with Nodejs.12
JSON structure
API Gateway Chat Stage and deploy
Remember to DELPLOY api ws