How do you count items in DynamoDB?

Use Select: 'COUNT' on a Query or Scan to count matching items without returning them. Each response counts only up to 1 MB scanned, so you must paginate with LastEvaluatedKey and sum the Count values for a full total. For an approximate table total, read ItemCount from DescribeTable.

Counting matched items exactly

Set Select to COUNT on a Query (for one partition key) or Scan (whole table). The response returns Count and ScannedCount but no item data. If the scanned data exceeds 1 MB, the operation stops and returns LastEvaluatedKey — keep calling and adding up Count until it is absent.

Count vs ScannedCount

  • Count — items matching your key/filter conditions in this page.
  • ScannedCount — items examined before filtering. A filter expression narrows results but does not reduce what was scanned (or its cost).

The cheap approximation

DescribeTable returns ItemCount, a table-wide estimate updated roughly every six hours. It is free and instant, but not real-time — good for dashboards, not for exact totals.

Go deeper

Read count, sum, and aggregate in DynamoDB and build count queries with the Expression Builder. Download DynoTable to run counts against your tables.

不必透過主控台就能操作 DynamoDB

DynoTable 是一款快速的 DynamoDB 桌面用戶端 — 瀏覽表格、執行 SQL 風格的查詢,並在本機編輯項目。