Last updated: Feb 26, 2024
Reading time·2 min
To get the item count of a DynamoDB table, you have to:
Overview
tab scroll down to the Items summary
section.Get live item count
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.
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.
The Item count
, Table size
and Average item size
metrics get automatically
updated every 6 hours.
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
.
aws dynamodb scan --table-name "YOUR_TABLE" --select "COUNT"
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.
You can learn more about the related topics by checking out the following tutorials: