I want to create small live chat app with socket connections based on AWS serverless architecture. For this I was created socket and 3 lambda functions (connect, sendMessage and disconnect). I will have many chats and users can enter to the chat and create connection to socket for this chat. One chat can have many connections and when users leave the chat I need to remove this connection. For implement this I can’t understand how to add connection to DynamoDB, because y need to get all connection to the chat for send messages to all of them, and how i can get chat by connectionID for removing this connection from chat.
First labmbda function (connect) have connectionId and chatId with this 2 ids I can create one line in Dyanamo DB.
PK chat#xxx1 SK connection#yyy1
PK chat#xxx1 SK connection#yyy2
PK chat#xxx1 SK connection#yyy3
Second labmda function (sendMessage) I can get all connection by PK to send messages.
But in function disconnect I do not have chatId, I have only connectionId, and I need to remove this connection: PK chat#xxx1 SK connection#yyy2. Yes I can scan all table and find this connection, but i what to use single table design, and this teble will have all messages and all information about chats. A lot of information, and scan all table is very slow. Can you explain me, how to get one item by SK?
I have read a lot of documentation but i didn’t find answer for my question.
Ilya Shcherbakov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.