Get the Item Count of a Dynamodb Table

avatar

Borislav Hadzhiev

Fri Sep 24 20212 min read

Table of Contents #

  1. Get the Item Count of a Dynamodb Table with AWS Console
  2. Get the Item Count of a Dynamodb Table with the AWS CLI

Get the Item Count of a Dynamodb Table with AWS Console #

To get the item count of a dynamodb table, you have to:

  1. Open the AWS Dynamodb console and click on your table's name
  2. In the Overview tab scroll down to the Items summary section
  3. Click on the Get live item count button

get live item count button

  1. Click on the Start scan button

start scan button

Under the hood a scan operation is performed on the table. This means that dynamodb has to read every single item in the table to calculate the total count.

It's best to perform the Live count action at times where your production-critical table is used the least. Performing a scan on a large table might exhaust its read capacity units and throttle user requests.

If you don't need the most up to date metric for the item count in your table, you can look at the Items summary section in your table's Overview tab.

items summary section

The Item count, Table size and Average item size metrics get automatically updated every 6 hours.

Get the Item Count of a Dynamodb Table with the AWS CLI #

In order to get the item count of a dynamodb table, using the AWS CLI, you have to run the dynamodb scan command, setting the select parameter to COUNT.

shell
aws dynamodb scan --table-name "YOUR_TABLE" --select "COUNT"

count items aws cli

The --select parameter of the scan command allows us to filter the output, in our case we only care about the total item count, rather than the items themselves.

The command's output shows that the ScannedCount is equal to the Count, meaning dynamodb had to get every item in order to calculate the total count.

This is very inefficient, can exhaust a table's read capacity units and throttle user requests.

Further Reading #

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee