liveBook · Manning

DynamoDB Query operation

As explained in Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

The DynamoDB Query operation retrieves multiple items that share a partition-key value and can optionally apply sort-key conditions and post-query filters.

The DynamoDB Query operation retrieves multiple items that share a partition-key value. A table must use a partition key and sort key to return a collection of items; the partition key identifies the group, while the sort key orders items within it. section 12.4.2 section 12.15

Build a query around key conditions, then refine or paginate the result:

  • Use FilterExpression for attributes that are not keys, such as task category or due date. DynamoDB applies the filter after inspecting every item returned by the key condition, so filtering does not use an index. section 12.4.2
  • Query a global secondary index when the required access pattern uses another partition key, such as category, instead of the table's uid key. section 12.4.4

Listing Emma's tasks

A task listing queries todo-task with KeyConditionExpression set to uid = :uid, optionally adds a sort-key continuation value, and filters for overdue or due-today tasks. The command node index.js task-ls emma shopping demonstrates the surrounding application use case.

Query is efficient for known key access patterns, while Scan searches every table item and is less efficient. Strongly consistent reads can avoid stale data, but reads from global secondary indexes are always eventually consistent. section 12.15

How Amazon Web Services in Action, Third Edition: An in-depth guide to AWS covers it

How deep it goes
Explains request expressions, filters, pagination, secondary indexes, and efficiency limits, but does not detail lower-level service internals.
Examples
Uses user task listings, overdue and due-date filters, stock-price ranges, and category-index queries.
What it assumes
Assumes basic DynamoDB keys and items, while distinguishing single-item getItem retrieval from multi-item queries.
What you can do after
Apply it via the AWS SDK to retrieve keyed collections, filter results, paginate listings, and query a global secondary index.
How it connects
Connects partition keys, sort keys, filter expressions, global secondary indexes, scans, pagination, and consistency.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Amazon Web Services in Action, Third Edition: An in-depth guide to AWS. The section links point to the parts of the book it draws on.