Which statement correctly describes a key difference between a Global Secondary Index (GSI) and a Local Secondary Index (LSI) in DynamoDB?
Think about which index type allows a different partition key from the main table.
A Global Secondary Index (GSI) allows a different partition key and sort key from the base table, enabling queries on different attributes. A Local Secondary Index (LSI) shares the same partition key but uses a different sort key. LSIs must be created when the table is created.
You have a DynamoDB table with a partition key 'UserID' and sort key 'OrderDate'. You want to query orders by 'ProductCategory' regardless of user. Which index type should you create?
Remember that LSIs share the same partition key as the base table.
To query by 'ProductCategory' regardless of 'UserID', you need an index with 'ProductCategory' as partition key. Only a Global Secondary Index (GSI) allows a different partition key. LSIs must share the base table's partition key.
Your DynamoDB table uses an LSI. What happens if the total size of all items with the same partition key exceeds 10 GB?
Consider DynamoDB's hard limits on LSI size per partition key.
LSIs have a strict limit of 10 GB per partition key. If a write causes this limit to be exceeded, DynamoDB rejects the write with a validation error. It does not automatically repartition or delete data.
You want to restrict a user to only query a specific Global Secondary Index (GSI) on a DynamoDB table. Which IAM policy condition is required?
Think about which IAM condition key controls access to indexes.
The IAM condition key 'dynamodb:IndexName' allows you to restrict actions to a specific index name, including GSIs. 'dynamodb:TableName' controls table access, but not specific indexes.
You have a DynamoDB table with a GSI that is rarely queried but has high write traffic. What is the best practice to optimize cost and performance?
Think about how to reduce unnecessary writes to the GSI.
Sparse indexes reduce write costs and improve performance by only indexing items that have the GSI partition key attribute. This avoids writing all items to the GSI when not needed.