Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting recent N items from DynamoDB

I just started figuring out DynamoDB.

I have a simple table has date attribute(ex. 20160101) as HASH and created_at attribute(ex. 20160101185332) as RANGE.

I'd like to get latest N items from the table.

First, SCAN command does not have ScanIndexForward option. I think it's not possible with SCAN.

Next, QUERY command. It seems to be work if I repeat QUERY command several times to get enough number of items(cuz, I don't know how many items have same key value). - for example, I can query using today first and repeat for the day before if the result does not give enough items.

How can I do the job more efficiently? Or, can I query without KEY value?

like image 566
Hongseok Yoon Avatar asked Jan 19 '16 13:01

Hongseok Yoon


People also ask

How do I get items from DynamoDB?

To read an item from a DynamoDB table, use the GetItem operation. You must provide the name of the table, along with the primary key of the item you want. The following AWS CLI example shows how to read an item from the ProductCatalog table. With GetItem , you must specify the entire primary key, not just part of it.

Does DynamoDB query return all items?

The Query operation in Amazon DynamoDB finds items based on primary key values. You must provide the name of the partition key attribute and a single value for that attribute. Query returns all items with that partition key value.

What are the two ways of retrieving data from a DynamoDB table?

In Amazon DynamoDB, you can use either the DynamoDB API, or PartiQL, a SQL-compatible query language, to query an item from a table. With Amazon DynamoDB the Query action lets you retrieve data in a similar fashion. The Query action provides quick, efficient access to the physical locations where the data is stored.

How do I sort DynamoDB query results?

You can use the sort-key and apply the ScanIndexForward parameter in a query to sort in either ascending or descending order. Here I limit items returned to 1. Save this answer.


1 Answers

as you described your table, you cant do it more efficiently, and you cant query dynamodb without KEY(hash) value

look at the answer here: dynamodb get earliest inserted distinct values from a table

like image 105
Eyal Ch Avatar answered Oct 11 '22 15:10

Eyal Ch