0
0
AWScloud~30 mins

Secondary indexes (GSI, LSI) in AWS - Mini Project: Build & Apply

Choose your learning style9 modes available
Create a DynamoDB Table with Secondary Indexes
📖 Scenario: You are building a simple inventory system using AWS DynamoDB. You want to create a table that stores product information. To efficiently query products by category and by supplier, you will add secondary indexes.
🎯 Goal: Create a DynamoDB table named Products with a primary key and add a Global Secondary Index (GSI) and a Local Secondary Index (LSI) to support queries by Category and Supplier.
📋 What You'll Learn
Create a DynamoDB table named Products with ProductID as the partition key (string).
Add a Local Secondary Index (LSI) named CategoryIndex with ProductID as partition key and Category as sort key.
Add a Global Secondary Index (GSI) named SupplierIndex with Supplier as partition key and Price as sort key.
Set the billing mode to PAY_PER_REQUEST.
💡 Why This Matters
🌍 Real World
Secondary indexes in DynamoDB help you query your data efficiently without scanning the entire table, which is important for performance and cost.
💼 Career
Understanding how to configure GSIs and LSIs is essential for AWS cloud architects and developers working with NoSQL databases to optimize data access patterns.
Progress0 / 4 steps
1
Create the DynamoDB table with primary key
Create a DynamoDB table resource named Products with ProductID as the partition key of type S (string). Use PAY_PER_REQUEST billing mode.
AWS
Need a hint?

Define AttributeDefinitions with ProductID as string and set KeySchema with ProductID as partition key.

2
Add Local Secondary Index (LSI) for Category
Add a Local Secondary Index named CategoryIndex to the Products table. Use ProductID as the partition key and Category as the sort key. Define Category as a string attribute in AttributeDefinitions.
AWS
Need a hint?

Remember that LSI uses the same partition key as the table and a different sort key.

3
Add Global Secondary Index (GSI) for Supplier
Add a Global Secondary Index named SupplierIndex to the Products table. Use Supplier as the partition key and Price as the sort key. Define Supplier and Price as string attributes in AttributeDefinitions. Set the projection type to ALL.
AWS
Need a hint?

GSI can have different partition and sort keys than the table. Add both Supplier and Price to AttributeDefinitions.

4
Complete the DynamoDB table configuration
Ensure the full DynamoDB table resource named Products includes PAY_PER_REQUEST billing mode, the primary key, the Local Secondary Index CategoryIndex, and the Global Secondary Index SupplierIndex with all attribute definitions.
AWS
Need a hint?

Review the full table resource to ensure all parts are included correctly.