liveBook · Manning

Secondary index

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

A global secondary index is a DynamoDB index that can use a partition key different from the parent table's partition key and is maintained asynchronously with the table.

A global secondary index is an automatically maintained projection of a DynamoDB table that supports efficient queries through an additional key. Its partition key can differ from the parent table's partition key, and its key need not be unique. section 12.4.3 section 12.15

Use an index when the table's primary key cannot answer a recurring access pattern. In the todo-task example, category becomes the index partition key and tid becomes its sort key, enabling tasks to be queried by category. section 12.4.2 section 12.4.3

Plan and operate a global secondary index with these constraints:

  • Wait for creation to finish and inspect its status with describe-table before relying on the index. section 12.4.4
  • Budget for index storage and additional write capacity, because table writes update the index asynchronously. section 12.4.3

Query tasks by category

Create category-index on todo-task with category as the partition key, tid as the sort key, and an ALL projection. Query it with task-la shopping to retrieve shopping tasks for John and Emma. section 12.4.4

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

How deep it goes
Explains projections, key schemas, asynchronous maintenance, CLI creation, readiness checks, queries, consistency, capacity, and cost.
Examples
Uses a todo-task category-index to retrieve shopping tasks with category as partition key and tid as sort key.
What it assumes
Assumes familiarity with DynamoDB tables and primary keys while introducing secondary-index lookups from the limitation of key-only retrieval.
What you can do after
Apply it via AWS CLI and Node.js to create, verify, and query a DynamoDB global secondary index.
How it connects
Connects DynamoDB with partition keys, sort keys, query operations, eventual consistency, local secondary indexes, and provisioned capacity.

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.