Get the Item Count of a Dynamodb Table

avatar
Borislav Hadzhiev

Last updated: Feb 26, 2024
2 min

banner

# 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 when 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.

I've also written a tutorial on how to provision and configure a Dynamodb table using AWS CDK.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.