Introduction
DynamoDB enables faster access to the data using indexes. We saw how to fetch items using primary key indexes in the previous chapter. Sometimes, accessing data only through primary keys is just not enough. In order to avail data access through non-primary key attributes, we need to create secondary indexes. When we create a secondary index, DynamoDB copies the projected attributes along with the key attributes. The secondary index allows you to scan or query the way we do it for a table. There are two types of secondary indexes that we can create on the DynamoDB table: a Global Secondary Index (GSI) and a Local Secondary Index (LSI).
A GSI allows you to query data on the complete table dataset, as it has completely different hash and range keys compared to a LSI. A LSI restricts you to querying data on only one partition as it has the same hash key as that of the table, so the query is local for a given hash key. A LSI needs to be created at the time of the table creation...