Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve all items from DynamoDB using query?

I am trying to retrieve all items in a dynamodb table using a query. Below is my code:

import boto.dynamodb2 from boto.dynamodb2.table import Table from time import sleep  c    = boto.dynamodb2.connect_to_region(aws_access_key_id="XXX",aws_secret_access_key="XXX",region_name="us-west-2")  tab  = Table("rip.irc",connection=c)  x    = tab.query()  for i in x:     print i     sleep(1) 

However, I recieve the following error:

ValidationException: ValidationException: 400 Bad Request {'message': 'Conditions can be of length 1 or 2 only', '__type': 'com.amazon.coral.validate#ValidationException'} 

The code I have is pretty straightforward and out of the boto dynamodb2 docs, so I am not sure why I am getting the above error. Any insights would be appreciated (new to this and a bit lost). Thanks

EDIT: I have both an hash key and a range key. I am able to query by specific hash keys. For example,

x = tab.query(hash__eq="2014-01-20 05:06:29") 

How can I retrieve all items though?

like image 347
dlaser Avatar asked Feb 02 '14 20:02

dlaser


People also ask

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.

How do I get items from DynamoDB table?

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.

Can you use SQL to query DynamoDB?

You now can use a SQL-compatible query language to query, insert, update, and delete table data in Amazon DynamoDB.


1 Answers

Ahh ok, figured it out. If anyone needs:

You can't use the query method on a table without specifying a specific hash key. The method to use instead is scan. So if I replace:

x    = tab.query() 

with

x    = tab.scan() 

I get all the items in my table.

like image 152
dlaser Avatar answered Sep 28 '22 11:09

dlaser