To get the item count of a DynamoDB table, you have to:
Overviewtab scroll down to the
Get live item countbutton
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
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
aws dynamodb scan --table-name "YOUR_TABLE" --select "COUNT"
--select parameter of the
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
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: