Secondary Index in a DynamoDB Table

Secondary Index in a DynamoDB Table

Takes 45 mins

There are two methods to access the data in DynamoDB—scan and query. Both data read options have their separate limitations. Asking for a primary key in the query method is quick, but it can only give us a limited set of access patterns. Scanning can give us any access pattern, but it’s slow and expensive.

image

In addition to the query method, there is a second option called secondary index. It’s comparatively cheaper, and it gives us more accessibility patterns.

In this lab, we’ll learn to run a query using GSIGlobal secondary index and LSILocal secondary index.

Lab tasks

  • Create a table.
  • Add items to the table.
  • Check indexes and run a query.
  • Run the global secondary index.
  • Run the local secondary index.
  • Clean up.

Architecture diagram

The following is the high-level architecture diagram of how to create a secondary index in a DynamoDB table.

image