0
0
DynamoDBquery~30 mins

GSI key selection strategy in DynamoDB - Mini Project: Build & Apply

Choose your learning style9 modes available
GSI Key Selection Strategy in DynamoDB
📖 Scenario: You are building a DynamoDB table to store information about online orders for a small e-commerce business. You want to efficiently query orders by customer and by order status using Global Secondary Indexes (GSIs).
🎯 Goal: Create a DynamoDB table with a primary key and add a Global Secondary Index (GSI) with a suitable partition key and sort key to support querying orders by customer and order status.
📋 What You'll Learn
Create a DynamoDB table named Orders with OrderId as the partition key.
Add a GSI named CustomerStatusIndex with CustomerId as the partition key and OrderStatus as the sort key.
Use the correct attribute definitions for all keys.
Set the projection type of the GSI to ALL.
💡 Why This Matters
🌍 Real World
E-commerce platforms often need to query orders by customer and status quickly. Using GSIs with well-chosen keys improves query speed and reduces costs.
💼 Career
Understanding how to design GSIs is essential for database engineers and backend developers working with DynamoDB to optimize data access patterns.
Progress0 / 4 steps
1
Create the DynamoDB table with primary key
Create a DynamoDB table named Orders with OrderId as the partition key of type S (string). Define the attribute OrderId in the attribute definitions.
DynamoDB
Need a hint?

Use OrderId as the HASH key in KeySchema and define it in AttributeDefinitions with type S.

2
Add attribute definitions for GSI keys
Add attribute definitions for CustomerId and OrderStatus with type S (string) to the existing attribute definitions.
DynamoDB
Need a hint?

Remember to add both CustomerId and OrderStatus as string attributes in AttributeDefinitions.

3
Define the Global Secondary Index (GSI)
Add a Global Secondary Index named CustomerStatusIndex with CustomerId as the partition key (HASH) and OrderStatus as the sort key (RANGE). Set the projection type to ALL.
DynamoDB
Need a hint?

Define the GSI with CustomerId as HASH key and OrderStatus as RANGE key, and set projection type to ALL.

4
Complete the table creation configuration
Add the BillingMode set to PAY_PER_REQUEST to the table configuration to enable on-demand capacity mode.
DynamoDB
Need a hint?

Set BillingMode to PAY_PER_REQUEST to use on-demand capacity.