You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
A DynamoDB table's primary key supports one access pattern. When you need to query data by different attributes, you create secondary indexes. DynamoDB supports two types: Global Secondary Indexes (GSI) and Local Secondary Indexes (LSI).
Consider a table with a primary key of UserId:
Table: Users (PK = UserId)
UserId Name Email Country
user-001 Alice alice@example.com UK
user-002 Bob bob@example.com US
user-003 Charlie charlie@example.com UK
You can efficiently look up a user by UserId, but what if you need to:
Without indexes, you would need a Scan (reading every item). Secondary indexes let you Query efficiently by different attributes.
A GSI has its own partition key and sort key, which can be any attributes from the table:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.