0
0
DynamoDBquery~5 mins

Why Scan reads the entire table in DynamoDB

Choose your learning style9 modes available
Introduction

Scan reads the entire table because it looks at every item to find the data you want. It does not use indexes or keys to jump directly to specific items.

When you want to get all items from a table without filtering by key.
When you need to check or count all records in a table.
When you want to find items based on attributes that are not keys.
When you have a small table and performance is not a big concern.
Syntax
DynamoDB
Scan
  -- TableName: name of the table
  -- Optional FilterExpression to narrow results
  -- Returns all items matching the filter or all if no filter

Scan reads every item, so it can be slow for big tables.

Use FilterExpression to reduce returned data but Scan still reads all items internally.

Examples
Reads all items from the 'Products' table.
DynamoDB
Scan
  TableName: 'Products'
Reads all items but returns only those with OrderStatus 'Pending'.
DynamoDB
Scan
  TableName: 'Orders'
  FilterExpression: 'OrderStatus = :status'
  ExpressionAttributeValues: { ':status': {"S": "Pending"} }
Sample Program

This command reads every item in the 'Products' table and returns them all.

DynamoDB
aws dynamodb scan --table-name Products
OutputSuccess
Important Notes

Scan reads every item, so it uses more read capacity and takes longer on large tables.

Use Query instead when you can filter by primary key for better performance.

Summary

Scan reads the whole table item by item.

It is simple but slow for big tables.

Use Scan only when you cannot use Query with keys.