2

Folks, Retrieving all items from a DynamoDB table, I would like to replace the scan operation with a query.

Currently I am pulling in all the table's data via the following (python):

drivertable = Table(url['dbname'])
all_drivers = []
all_drivers_query = drivertable.scan()
for x in all_drivers_query:
  all_drivers.append(x['number'])

How would i change this to use the query API?

Thanks!

1
  • Why would you want to do that ? Scan() is for full table scans (i.e. retrieve all values) while query() is for getting specific values (hash or hash + range) ... What is your use case ? What do you think query will bring you that scan does not ? Commented Dec 16, 2014 at 13:53

2 Answers 2

3
+50

There is no way to query and get the entire results of the table. As of right now, you have a few options if you want to get all of your data out of a DynamoDB, and all of them involve actually reading the data out of DynamoDB:

  1. Scan the table. It can be done faster with the expense of using much more read capacity by using a parallel scan
  2. Export your data using AWS Data Pipelines. You can configure the export job for where and how it should store your data.
  3. Using one of the AWS event platforms for new data and denormalize it. For all new data you can get a time-ordered stream of all updates to the table from DynamoDB Update Streams or process events using AWS Lambda
Sign up to request clarification or add additional context in comments.

Comments

2

You can't query an entire table. Query is used to retrieve a set of items by supplying a hash key (part of the complex primary key hash-range of the table).

One can not use query without knowing the hash keys.

EDIT as a bounty was added to this old question that asks:

How do I get a list of hashes from DynamoDB?

Well - In Dec 2014 you still can't ask via a single API for all hash keys of a table. Even if you go and put a GSI you still can't get a DISTINCT hash count.

The way I would solve this is with de-normalization. Keep another table with no range key and put every hash there together with the main table. This adds house-keeping overhead to your application level (mainly when removing), but solves the problem you asked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.