0
0
DynamoDBquery~30 mins

Creating GSI in DynamoDB - Try It Yourself

Choose your learning style9 modes available
Creating a Global Secondary Index (GSI) in DynamoDB
📖 Scenario: You are managing a DynamoDB table for an online bookstore. The table stores information about books, including their BookID, Title, Author, and Genre. You want to create a Global Secondary Index (GSI) to efficiently query books by their Author.
🎯 Goal: Build a DynamoDB table schema with a Global Secondary Index (GSI) named AuthorIndex that uses Author as the partition key. This will allow quick lookups of books by author.
📋 What You'll Learn
Create a DynamoDB table named Books with BookID as the primary partition key.
Add a Global Secondary Index (GSI) named AuthorIndex with Author as the partition key.
Set the projection type of the GSI to ALL to include all attributes.
Specify the provisioned throughput for both the table and the GSI.
💡 Why This Matters
🌍 Real World
Global Secondary Indexes let you query DynamoDB tables efficiently using different keys than the primary key. This is common in real-world apps needing flexible search options.
💼 Career
Understanding how to create and configure GSIs is essential for backend developers and database administrators working with DynamoDB to optimize data access patterns.
Progress0 / 4 steps
1
Create the DynamoDB table schema
Create a DynamoDB table schema named Books with BookID as the primary partition key of type S (string). Define the attribute definitions for BookID, Title, Author, and Genre all as type S.
DynamoDB
Need a hint?

Define the table name, attribute definitions for all attributes as strings, and set BookID as the partition key in the key schema.

2
Add Global Secondary Index (GSI) configuration
Add a GlobalSecondaryIndexes section to the table schema. Create a GSI named AuthorIndex with Author as the partition key (HASH). Set the projection type to ALL and provisioned throughput to 5 read and 5 write capacity units.
DynamoDB
Need a hint?

Inside GlobalSecondaryIndexes, define the index name, key schema with Author as partition key, projection type as ALL, and provisioned throughput.

3
Verify attribute definitions include GSI key
Ensure the AttributeDefinitions section includes the Author attribute with type S because it is used as the partition key in the GSI.
DynamoDB
Need a hint?

Make sure Author is listed in AttributeDefinitions with type S because it is the GSI partition key.

4
Complete the table creation JSON with all parts
Combine all parts to form the complete DynamoDB table creation JSON. It should include TableName, AttributeDefinitions, KeySchema, ProvisionedThroughput, and GlobalSecondaryIndexes with the AuthorIndex GSI.
DynamoDB
Need a hint?

Make sure all parts are included together in one JSON object to create the table with the GSI.