How to get the row count of a table instantly in DynamoDB?

kxxoling picture kxxoling · Jul 13, 2015 · Viewed 34.4k times · Source

I'm using boto.dynamodb2, and it seems I can use Table.query_count(). However it had raised an exception when no query filter is applied.

What can I do to fix this?

BTW, where is the document of filters that boto.dynamodb2.table.Table.Query can use? I tried searching for it but found nothing.

Answer

JaredHatfield picture JaredHatfield · Jul 16, 2015

There are two ways you can get a row count in DynamoDB.

The first is performing a full table scan and counting the rows as you go. For a table of any reasonable size this is generally a horrible idea as it will consume all of your provisioned read throughput.

The other way is to use the Describe Table request to get an estimate of the number of rows in the table. This will return instantly, but will only be updated periodically per the AWS documentation.

The number of items in the specified index. DynamoDB updates this value approximately every six hours. Recent changes might not be reflected in this value.