Quest · quest 3
Fetch All Pokémon
Imagine you need to find all the Pokémon in your table, not just one by name. The Scan operation lets you read every item in a DynamoDB table, one page at a time.
Key takeaways
- Scan reads all items from a table without needing to know specific keys.
- Each request reads up to 1 MB; continue while LastEvaluatedKey is present.
- FilterExpression is applied after reading and does not reduce consumed read capacity.
What is a Scan Operation?
Think of your DynamoDB table like a huge toy box full of Pokémon cards. A Scan is like dumping out the entire toy boxand looking through every single card one by one to see what you have.
You don't need to know the name of a specific Pokémon beforehand—you just want to see everything that's in there! DynamoDB will show you all the cards (items), but it might give them to you in small groups (pages) if there are too many to look at all at once.
How Scan Works
When you perform a Scan operation:
- DynamoDB reads every item in the table.
- A request reads up to 1 MB before any filter is applied.
- You can add filters to only show certain Pokémon, but DynamoDB still looks at everything first.
- To get the next page, you use the
LastEvaluatedKeyfrom the previous response.
Scan Operation Example
Here's the AWS SDK v3 request shape. KeySync parses this code and runs it against deterministic fixtures; it never connects to AWS.
One request returns only one page. To fetch all items, repeat the scan with ExclusiveStartKey until the response has no LastEvaluatedKey. The @aws-sdk/lib-dynamodb package automatically converts DynamoDB's native format to JavaScript objects, making your code much cleaner!
Interactive Challenge
The example shows a scan operation on a Users table. Your task is to modify the TableName to "Pokemon"to scan our Pokémon table. Write your code in the editor below, then check the Solution tab to verify your answer.