I'm using AWS DynamoDB to store user session records for a web application.
Each record is of the following format:
uuid timestamp type
where
uuid
is a users id and partition keytimestamp
is a unix timestamp and sort keytype
is "connected" or "disconnected"
In our administrator dashboard I want to display a table with the latest XX sessions, with the newest session first.
Question: Using AWS DynamoDB, how can I query all sessions
in sorted order and with a defined limit?
Specifying a partition key
is required using a Query
A Scan does not return results in sorted order
All solutions I have seen seems a bit "hacky", and I suspect I have misunderstood something since this use case must be fairly common.
Im aware of this hacky solution:
- Define a variable to all rows with same value
- Create a secondary index and set the variable as partition key and timestamp as sortkey
- Query this secondary index (now all row has the same partition key)
I'm no expert in DynamoDB, but this solution appears to be a hack and in opposition to DynamoDB architecture.