somod-chat-service
Version:
Serverless Chat Service from SOMOD
13 lines (12 loc) • 534 B
JavaScript
import { DynamoDBClient, DeleteItemCommand } from "@aws-sdk/client-dynamodb";
import { marshall } from "@aws-sdk/util-dynamodb";
const dynamodb = new DynamoDBClient();
const WebsocketOnDisconnect = async (event) => {
const connectionId = event.requestContext.connectionId;
await dynamodb.send(new DeleteItemCommand({
TableName: process.env.CONNECTIONS_TABLE_NAME + "",
Key: marshall({ id: connectionId })
}));
return { statusCode: 200, body: "Disconnected." };
};
export default WebsocketOnDisconnect;