What is a Global Secondary Index (GSI) in DynamoDB?
A Global Secondary Index (GSI) is an index with a partition key and optional sort key that can be different from the base table's keys. It allows querying data efficiently using alternate keys across all table data.
Click to reveal answer
beginner
What is a Local Secondary Index (LSI) in DynamoDB?
A Local Secondary Index (LSI) is an index that uses the same partition key as the base table but a different sort key. It allows querying data within the same partition using alternate sort keys.
Click to reveal answer
intermediate
Can you add a Global Secondary Index (GSI) after creating a DynamoDB table?
Yes, you can add a GSI to an existing DynamoDB table at any time without downtime.
Click to reveal answer
intermediate
Can you add a Local Secondary Index (LSI) after creating a DynamoDB table?
No, LSIs must be defined when the table is created and cannot be added later.
Click to reveal answer
intermediate
What is a key difference in storage between GSI and LSI?
LSIs share the same partition key and storage as the base table, while GSIs have their own storage and can have different partition keys.
Click to reveal answer
Which index type in DynamoDB can have a different partition key than the base table?
ALocal Secondary Index (LSI)
BGlobal Secondary Index (GSI)
CPrimary Key
DSort Key
✗ Incorrect
GSIs allow a different partition key from the base table, enabling flexible queries.
When can you add a Local Secondary Index (LSI) to a DynamoDB table?
AOnly during table update
BAnytime after table creation
COnly during table creation
DLSIs cannot be added at all
✗ Incorrect
LSIs must be defined when creating the table and cannot be added later.
Which index type shares the same partition key as the base table?
AGlobal Secondary Index (GSI)
BBoth GSI and LSI
CNeither GSI nor LSI
DLocal Secondary Index (LSI)
✗ Incorrect
LSI uses the same partition key but a different sort key.
What happens to storage when you create a Global Secondary Index (GSI)?
AGSI uses separate storage from the base table
BGSI shares storage with the base table
CGSI does not use any storage
DGSI storage is temporary
✗ Incorrect
GSIs have their own storage separate from the base table.
Which index type can be added to a DynamoDB table without downtime?
AGlobal Secondary Index (GSI)
BLocal Secondary Index (LSI)
CNeither
DBoth
✗ Incorrect
GSIs can be added anytime without downtime; LSIs cannot be added after creation.
Explain the main differences between Global Secondary Index (GSI) and Local Secondary Index (LSI) in DynamoDB.
Think about keys, timing of creation, and storage.
You got /5 concepts.
Describe when and why you would use a Global Secondary Index (GSI) versus a Local Secondary Index (LSI).
Consider query needs and index flexibility.
You got /4 concepts.
Practice
(1/5)
1. What is the main difference between a Local Secondary Index (LSI) and a Global Secondary Index (GSI) in DynamoDB?
easy
A. LSI can have a different partition key, but GSI must use the main table's partition key.
B. LSI uses the same partition key as the main table, but GSI can use a different partition key.
C. LSI and GSI both require the same partition and sort keys as the main table.
D. LSI is only for read operations, while GSI is only for write operations.
Solution
Step 1: Understand LSI key structure
LSI shares the same partition key as the main table but allows a different sort key.
Step 2: Understand GSI key structure
GSI can have a completely different partition key and sort key from the main table.
Final Answer:
LSI uses the same partition key as the main table, but GSI can use a different partition key. -> Option B
Quick Check:
LSI shares partition key, GSI can differ [OK]
Hint: LSI shares partition key; GSI can change both keys [OK]
Common Mistakes:
Thinking LSI can have a different partition key
Assuming GSI must use main table keys
Confusing read/write capabilities of indexes
2. Which of the following is the correct syntax to define a Global Secondary Index (GSI) in a DynamoDB table using AWS CloudFormation?
GSI uses GlobalSecondaryIndexes with HASH key [OK]
Hint: GSI uses GlobalSecondaryIndexes with HASH key [OK]
Common Mistakes:
Using LocalSecondaryIndexes for GSI
Setting KeyType to RANGE for partition key
Incorrect projection types or syntax errors
3. Given a DynamoDB table with a Global Secondary Index (GSI) on attribute Category as partition key and Price as sort key, what will the following query return?
Query on GSI where Category = 'Books' and Price between 10 and 20
medium
A. All items with Category 'Books' and Price between 10 and 20
B. All items with Price between 10 and 20 regardless of Category
C. All items with Category 'Books' regardless of Price
D. An error because Price cannot be used in query conditions
Solution
Step 1: Understand GSI query conditions
Query on GSI requires specifying the partition key (Category = 'Books') and can filter by sort key range (Price between 10 and 20).
Step 2: Interpret the query result
The query returns all items matching Category 'Books' with Price in the specified range.
Final Answer:
All items with Category 'Books' and Price between 10 and 20 -> Option A
Quick Check:
GSI query filters partition and sort keys correctly [OK]
Hint: Query GSI with partition key + sort key range filters [OK]
Common Mistakes:
Ignoring partition key in query
Thinking sort key can't be filtered
Expecting error on valid query
4. You created a Local Secondary Index (LSI) on a DynamoDB table but your query on the LSI returns no results even though matching items exist. What is the most likely cause?
medium
A. The LSI was created with a different partition key than the main table.
B. The query used a filter expression instead of a key condition.
C. The query did not specify the same partition key as the main table.
D. LSIs do not support queries, only scans.
Solution
Step 1: Recall LSI key requirements
LSI shares the same partition key as the main table, so queries must specify that partition key.
Step 2: Analyze query behavior
If the query does not specify the partition key, no results will be returned because partition key is mandatory for queries on LSI.
Final Answer:
The query did not specify the same partition key as the main table. -> Option C
Quick Check:
LSI queries require main table partition key [OK]
Hint: LSI queries must include main table partition key [OK]
Common Mistakes:
Assuming LSI can have different partition key
Using filter instead of key condition for partition key
Believing LSI does not support queries
5. You have a DynamoDB table with a partition key UserId and sort key OrderDate. You want to efficiently query all orders by Status and sort them by OrderAmount. Which secondary index should you create and how?
hard
A. Create a Global Secondary Index with partition key Status and sort key OrderAmount.
B. Create a Local Secondary Index with partition key UserId and sort key Status.
C. Create a Global Secondary Index with partition key UserId and sort key Status.
D. Create a Local Secondary Index with partition key Status and sort key OrderAmount.
Solution
Step 1: Identify query requirements
You want to query by Status (different from main partition key) and sort by OrderAmount.
Step 2: Choose index type and keys
Since Status is different from main partition key, use a Global Secondary Index with Status as partition key and OrderAmount as sort key.
Final Answer:
Create a Global Secondary Index with partition key Status and sort key OrderAmount. -> Option A
Quick Check:
GSI allows different partition and sort keys [OK]
Hint: Use GSI when partition key differs from main table [OK]
Common Mistakes:
Trying to use LSI with different partition key
Swapping partition and sort keys incorrectly
Choosing wrong index type for query pattern
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.