0
0
DynamoDBquery~30 mins

Index projection types (ALL, KEYS_ONLY, INCLUDE) in DynamoDB - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding DynamoDB Index Projection Types
📖 Scenario: You are building a simple online bookstore database using DynamoDB. You want to create a secondary index to quickly find books by their genre. To optimize your index, you need to understand how to project attributes into the index using different projection types.
🎯 Goal: Create a DynamoDB table with a Global Secondary Index (GSI) on the Genre attribute. Configure the index to use different projection types: ALL, KEYS_ONLY, and INCLUDE. This will help you learn how each projection type affects the data stored in the index.
📋 What You'll Learn
Create a DynamoDB table named Books with primary key BookID (string).
Add a Global Secondary Index named GenreIndex with partition key Genre (string).
Set the index projection type to ALL in Step 1.
Change the index projection type to KEYS_ONLY in Step 2.
Change the index projection type to INCLUDE and include the Title and Author attributes in Step 3.
Complete the final table definition with the INCLUDE projection type in Step 4.
💡 Why This Matters
🌍 Real World
In real-world applications, choosing the right projection type for your DynamoDB indexes helps optimize performance and cost by controlling which attributes are copied into the index.
💼 Career
Database developers and cloud engineers often configure DynamoDB indexes to improve query speed and reduce costs by selecting appropriate projection types.
Progress0 / 4 steps
1
Create DynamoDB table with GSI using ALL projection
Create a DynamoDB table named Books with primary key BookID of type string. Add a Global Secondary Index named GenreIndex with partition key Genre of type string. Set the index's ProjectionType to ALL.
DynamoDB
Need a hint?

Remember to define AttributeDefinitions for both BookID and Genre. Set ProjectionType inside the Projection object of the GSI.

2
Change the GSI projection type to KEYS_ONLY
Modify the existing GenreIndex in the Books table to set the ProjectionType to KEYS_ONLY instead of ALL.
DynamoDB
Need a hint?

Change the ProjectionType value inside the Projection object of the GenreIndex to KEYS_ONLY.

3
Change the GSI projection type to INCLUDE with specific attributes
Modify the GenreIndex to use INCLUDE as the ProjectionType. Include the attributes Title and Author in the NonKeyAttributes list.
DynamoDB
Need a hint?

Set ProjectionType to INCLUDE and add NonKeyAttributes with the list ["Title", "Author"] inside the Projection object.

4
Complete the table definition with INCLUDE projection type
Finalize the Books table definition with the GenreIndex using INCLUDE projection type including Title and Author as non-key attributes. Ensure all attributes and throughput settings are present.
DynamoDB
Need a hint?

Make sure the full table definition includes the GenreIndex with INCLUDE projection and the non-key attributes Title and Author. Also include provisioned throughput settings.