The goal of this code snippet is retreiving all connectionsids of a chat room to reply to a chat sendmessage command in the API Gateway WebSocket.
I have used PutCommand and GetCommand a lot, but today I'm using the QueryCommand for the first time.
The code Part 1, the DynamoDB call:
export async function ddbGetAllRoomConnections(room) {
const params = {
"TableName": "MessageTable",
"KeyConditionExpression": "#DDB_room = :pkey",
"ExpressionAttributeValues": {
":pkey": ""
},
"ExpressionAttributeNames": {
"#DDB_room": "room"
},
"ScanIndexForward": true,
"Limit": 100
};
console.log("ddbGetAllRoomConnections-1:",params);
const data = await ddbClient.send( new QueryCommand(params) );
console.log("ddbGetAllRoomConnections-2:",data);
return data;
}
The calling part:
const normalConnections = ddbGetAllRoomConnections(connData.lastroom);
if (typeof normalConnections.Items === 'undefined' || normalConnections.Items.length <= 0) {
throw new Error("Other Connections not found");
}
The following logfile entries are occuring in sequence:
logfile puzlle message1:
ddbGetAllRoomConnections-1: {
TableName: 'MessageTable',
KeyConditionExpression: '#DDB_room = :pkey',
ExpressionAttributeValues: { ':pkey': '' },
ExpressionAttributeNames: { '#DDB_room': 'room' },
ScanIndexForward: true,
Limit: 100
}
logfile puzlle message2:
ERROR Error: Other Connections not found
at Runtime.handler (file:///var/task/chat-messages.js:49:21)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
statusCode: 500
}
logfile puzlle message3:
END RequestId:
Waht irritates me is, the following sequence of occurences in the logfile:
- ddbGetAllRoomConnections-1: is coming correctly before the ddbClient.send command
- after the ddbClient.send command there is no ddbGetAllRoomConnections-2 log entry
- The next logentry is after the call of ddbGetAllRoomConnections showing the value undefined.
I tried also PartiQL per ExecuteCommand, then debugging with Dynobase I retrieved the code for the params section in the current setting.
So obvious, that I didn't see it. Thanks for pointing out.
Happy to help :-) Can you accept the answer? It gives me 10 points in stead of 1 :-)