Setting
In my TypeScript CDK project, I am dealing with the QueryInput-Object. The code snippet below shows how it's being used:
const params: QueryInput = {
TableName: criticalMessagesTableName,
ProjectionExpression: 'message',
KeyConditionExpression: 'myId = :myId and #ts BETWEEN :startTimestamp AND :endTimestamp',
ExpressionAttributeValues: {
':myId': { S: myId },
':startTimestamp': { N: String(startTimestamp) },
':endTimestamp': { N: String(startTimestamp + range - 1) },
},
ExpressionAttributeNames: {
'#ts': 'timestamp',
},
};
These are the values of the variables:
const myId = "some-string-based-partition-key-value";
const startTimestamp = 1630927923544; //ms since epoch value
const range = 60000; // some range in ms
The partition key of the table is myId
(String) and the sort key is timestamp
(Number).
Issue
Upon executing the query with an AWS.DynamoDB.DocumentClient instance, the error log points to the following problem:
{
"message": "Invalid KeyConditionExpression: Incorrect operand type for operator or function; operator or function: BETWEEN, operand type: M",
"code": "ValidationException",
"time": "2021-09-06T12:18:33.720Z",
"requestId": "M041V4RVD57IGRGNF7P7U15GRNVV4KQNSO5AEMVJF66Q9ASUAAJG",
"statusCode": 400,
"retryable": false,
"retryDelay": 43.99195146574429
}
It appears that the :startTimestamp and :endTimestamp are being interpreted as a map, leading to the error message. Any insights on this issue would be greatly appreciated.
Unfortunately, using <= and > as a workaround is not feasible due to the limitation of one operator per key in a KeyConditionExpression.
Any assistance or guidance on this specific to TypeScript documentation would be highly valuable.