Friday, November 11, 2011

Reading All Items from an Amazon SimpleDB Query Result

As you may have noticed select queries in SimpleDB have a maximum limit to the number of results returned and you will have to use the nextToken mechanism to get all results from a query. A solution was posted on aws forum but since I have modified it a bit, thought I will post it here again.

The variable sdb is the AmazonSimpleDB implementation class which in my case is the AmazonSimpleDBClient initialized and injected using Spring. Following is the relevant Spring configuration section (I am initializing an AmazonS3Client too which is not required if you are only using SimpleDB).

AWS ID and Secret values are read from the file in the classpath, which looks like below.

Don' forget to click the +1 button below if this post was helpful.

1 comment:

SDBExplorer said...

As the default value is 100, so Amazon SimpleDB will return results in chunks of 100. If the domain contains million of records then the continue cycle of next token could result the request time out or degrade the performance. I think, it would be better if we introduce sleep of few micro seconds before requesting next token. If we can set page size 2500 then again it will result better.