0
0
DynamoDBquery~30 mins

Single-table design methodology in DynamoDB - Mini Project: Build & Apply

Choose your learning style9 modes available
Single-table Design Methodology in DynamoDB
📖 Scenario: You are building a simple inventory system for a small store. Instead of using multiple tables, you will use a single DynamoDB table to store different types of items like products and categories.
🎯 Goal: Create a single DynamoDB table called StoreInventory that holds both product and category data using a single-table design. You will set up the initial data, add a configuration for item types, write the core logic to insert items with proper keys, and complete the table setup.
📋 What You'll Learn
Create a DynamoDB table named StoreInventory with a partition key called PK and a sort key called SK.
Add a configuration variable item_type to distinguish between products and categories.
Insert product and category items using the single-table design pattern with composite keys.
Complete the table setup with proper attribute definitions and key schema.
💡 Why This Matters
🌍 Real World
Single-table design in DynamoDB is used to efficiently store and query multiple related entity types in one table, reducing complexity and improving performance.
💼 Career
Understanding single-table design is essential for AWS developers and database engineers working with DynamoDB to build scalable and cost-effective applications.
Progress0 / 4 steps
1
Create the DynamoDB table structure
Create a DynamoDB table named StoreInventory with a partition key called PK and a sort key called SK. Use the AWS CLI command aws dynamodb create-table with the exact attribute names and key types.
DynamoDB
Need a hint?

Use the AWS CLI create-table command with --attribute-definitions and --key-schema options.

2
Add item type configuration
Create a variable called item_type and set it to the string "PRODUCT". This will help identify the type of item stored in the table.
DynamoDB
Need a hint?

Just assign the string "PRODUCT" to the variable item_type.

3
Insert product and category items using single-table design
Write two AWS CLI commands to insert one product and one category item into the StoreInventory table. Use PK and SK as composite keys. For the product, set PK to "PRODUCT#123" and SK to "METADATA#123". For the category, set PK to "CATEGORY#456" and SK to "METADATA#456". Include the item_type attribute with values "PRODUCT" and "CATEGORY" respectively.
DynamoDB
Need a hint?

Use aws dynamodb put-item with JSON for the --item parameter. Make sure keys and item_type match exactly.

4
Complete the table setup with attribute definitions and key schema
Add the final attribute definitions and key schema lines to the aws dynamodb create-table command to complete the StoreInventory table setup. Ensure the partition key is PK of type string and the sort key is SK of type string.
DynamoDB
Need a hint?

Make sure the create-table command includes both attribute definitions and key schema for PK and SK.