What is the main purpose of creating a Global Secondary Index (GSI) in DynamoDB?
Think about why you might want to search your data in a different way than the main key.
A Global Secondary Index lets you query your DynamoDB table using a different partition key and optional sort key than the main table. This helps when you want to find items based on attributes other than the primary key.
Given a DynamoDB table Orders with a GSI named CustomerIndex that uses CustomerID as the partition key, what will the following query return?
Query onCustomerIndexwhereCustomerID = 'C123'
Remember that a GSI lets you query by the alternate key defined in the index.
The query on the GSI using CustomerID = 'C123' returns all items where the CustomerID attribute matches 'C123'. This means all orders placed by that customer.
Which of the following JSON snippets correctly defines a Global Secondary Index named GSI1 with Category as the partition key and Price as the sort key?
The partition key must have KeyType as HASH and the sort key as RANGE.
Option C correctly sets Category as the partition key (HASH) and Price as the sort key (RANGE). The projection type ALL means all attributes are projected.
You want to optimize read performance and reduce storage costs for a GSI that queries only OrderID and OrderDate. Which projection type should you choose?
Think about projecting only the attributes you need to reduce storage and improve query speed.
The INCLUDE projection type lets you specify only the attributes you want in the index, reducing storage and improving read efficiency when you only need specific fields.
You run a query on a GSI named GSI2 with partition key UserID, but get the error: ValidationException: Query condition missed key schema element: UserID. What is the most likely cause?
Check if the query includes the partition key value required by the index.
The error means the query did not include the required partition key UserID in the key condition. Every query on a GSI must specify the partition key value.