Fri Sep 24 2021·2 min read
Photo by Jason Blackeye
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'll send you 1 email a week with links to all of the articles I've written that week