0
0
DynamoDBquery~10 mins

Basic scan operation in DynamoDB - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Basic scan operation
Start Scan Request
Read First Page of Items
Return Items to User
Check for More Pages?
NoEnd Scan
Yes
Read Next Page of Items
Back to Return Items
The scan operation reads all items in a table page by page, returning them until no more pages remain.
Execution Sample
DynamoDB
ScanRequest = {'TableName': 'Books'}
response = dynamodb.scan(**ScanRequest)
items = response['Items']
while 'LastEvaluatedKey' in response:
  response = dynamodb.scan(TableName='Books', ExclusiveStartKey=response['LastEvaluatedKey'])
  items.extend(response['Items'])
This code scans the entire 'Books' table, fetching all items page by page.
Execution Table
StepActionPage NumberItems ReturnedLastEvaluatedKey PresentNext Step
1Send scan request to 'Books' table15 itemsYesFetch next page
2Send scan request with ExclusiveStartKey25 itemsYesFetch next page
3Send scan request with ExclusiveStartKey33 itemsNoEnd scan
4No more pages-0 itemsNoStop
💡 No LastEvaluatedKey after page 3 means all items have been scanned.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
response.Itemsempty5 items5 items3 items13 items total
response.LastEvaluatedKeynonepresentpresentnonenone
itemsempty list5 items10 items13 items13 items
Key Moments - 2 Insights
Why do we need to check for LastEvaluatedKey after each scan?
Because DynamoDB returns data in pages, LastEvaluatedKey tells us if more pages exist. Without checking it (see execution_table rows 1-3), we might miss items.
What happens if we ignore LastEvaluatedKey and only scan once?
We only get the first page of items (row 1), missing the rest of the table data.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, how many items are returned after step 2?
A10 items
B3 items
C5 items
D13 items
💡 Hint
Check the 'Items Returned' column for step 2 and the 'items' variable in variable_tracker after step 2.
At which step does the scan operation know it has reached the last page?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'LastEvaluatedKey Present' column in execution_table; it is 'No' at step 3.
If the table had 20 items and each page returned 5 items, how many steps would the scan take?
A3 steps
B4 steps
C5 steps
D6 steps
💡 Hint
Each step returns 5 items; 20 items total means 4 full pages plus no more pages after the 4th.
Concept Snapshot
Basic Scan Operation in DynamoDB:
- Reads all items in a table, page by page.
- Each scan returns a page of items and a LastEvaluatedKey if more pages exist.
- Use LastEvaluatedKey to fetch next page.
- Repeat until no LastEvaluatedKey.
- Returns all items but can be costly for large tables.
Full Transcript
The Basic Scan Operation in DynamoDB reads all items from a table by fetching pages of data. Each scan request returns some items and a LastEvaluatedKey if there are more pages. The client checks this key to continue scanning until all items are retrieved. This process is shown step-by-step in the execution table, where each step fetches a page of items. Variables like response.Items and response.LastEvaluatedKey change after each scan. Beginners often wonder why checking LastEvaluatedKey is necessary; it ensures no items are missed. The visual quiz tests understanding of how many items are returned at each step and when the scan ends.