0
0
DynamoDBquery~30 mins

Table capacity modes (on-demand vs provisioned) in DynamoDB - Hands-On Comparison

Choose your learning style9 modes available
DynamoDB Table Capacity Modes: On-Demand vs Provisioned
📖 Scenario: You are building a simple inventory system for a small online store. You want to create a DynamoDB table to store product information. You need to decide how to set the table's capacity mode to handle read and write traffic efficiently.
🎯 Goal: Create a DynamoDB table named Products with a primary key ProductID. First, set up the table with the Provisioned capacity mode and specify read and write capacity units. Then, change the capacity mode to On-Demand to allow automatic scaling without specifying capacity units.
📋 What You'll Learn
Create a DynamoDB table named Products with ProductID as the partition key.
Set the table's capacity mode to Provisioned with ReadCapacityUnits set to 5 and WriteCapacityUnits set to 5.
Add a configuration variable to switch the capacity mode to On-Demand.
Update the table creation code to use the On-Demand capacity mode when the configuration variable is set.
💡 Why This Matters
🌍 Real World
Choosing the right capacity mode in DynamoDB helps manage costs and performance for applications with varying traffic patterns.
💼 Career
Understanding DynamoDB capacity modes is essential for cloud developers and database administrators working with AWS to optimize database scalability and cost.
Progress0 / 4 steps
1
Create DynamoDB table with Provisioned capacity mode
Write the AWS CLI command to create a DynamoDB table named Products with ProductID as the partition key. Set the capacity mode to Provisioned with ReadCapacityUnits and WriteCapacityUnits both set to 5.
DynamoDB
Need a hint?

Use aws dynamodb create-table with --provisioned-throughput to set capacity units.

2
Add configuration variable for capacity mode
Create a shell variable named CAPACITY_MODE and set it to PROVISIONED to represent the current capacity mode setting.
DynamoDB
Need a hint?

Use CAPACITY_MODE=PROVISIONED to set the variable.

3
Write conditional logic to choose capacity mode
Write a shell if statement that checks if CAPACITY_MODE equals PROVISIONED. If yes, set a variable CAPACITY_PARAMS to --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5. Otherwise, set CAPACITY_PARAMS to --billing-mode PAY_PER_REQUEST for on-demand mode.
DynamoDB
Need a hint?

Use if [ "$CAPACITY_MODE" = "PROVISIONED" ] to check the variable.

4
Create table using dynamic capacity mode parameter
Rewrite the AWS CLI command to create the Products table using the variable CAPACITY_PARAMS for capacity settings instead of hardcoding. This will allow switching between provisioned and on-demand modes by changing CAPACITY_MODE.
DynamoDB
Need a hint?

Use $CAPACITY_PARAMS in the create-table command to apply the selected capacity mode.