Working with DynamoDB
Learn to create, manage, and query data, ensuring high performance and seamless scalability.
We'll cover the following
Scan or query items in DynamoDB
Let's use the library analogy to explain the difference between scanning and querying items in DynamoDB.
In a library, we have numerous books, and we need to find a specific one. We can either browse through every book one by one (scan) or ask the librarian for help, who uses the library's organized system to quickly locate the book we're looking for (query).
Scan
Scanning is like browsing through every book in the library, one by one, until we find the one we need. In DynamoDB, a scan operation reads every item in the table and returns the items that meet our filtering criteria, if any. Scans can be slow and inefficient, especially for large tables, as they go through every item in the table, consuming more read capacity units. Scans are useful when we need to retrieve all or most of the items in a table, and we don't have a specific primary key to look up.
Query
Querying is like asking the librarian for help, who uses the library's organized system (e.g., books grouped by genre and author) to quickly find the book we're looking for. In DynamoDB, a query operation allows us to search for items based on the primary key (partition key and, optionally, the sort key) values. Queries are more efficient than scans, as they only search within a specific partition (or a range of sort key values) instead of scanning the entire table. Query operations return items that match our specified primary key values and any additional filtering criteria we provide.
Scan the table
By default, we will see a scan operation performed on the table, displaying all the items.
Get hands-on with 1200+ tech skills courses.