📖 Scenario: You work for a small company that uses a cloud database service called DynamoDB. You want to keep track of how much each department spends on database usage every month. This helps avoid unexpected high bills and keeps the budget under control.
🎯 Goal: Build a simple DynamoDB table and queries to record and check monthly costs per department. This will help you manage costs and prevent surprises in billing.
📋 What You'll Learn
Create a DynamoDB table named DepartmentCosts with Department as the partition key and Month as the sort key.
Add a configuration variable cost_threshold to set the maximum allowed monthly cost.
Write a query to find all departments with costs exceeding the cost_threshold for a given month.
Add a final step to update the table with a new cost entry for a department and month.
💡 Why This Matters
🌍 Real World
Companies use cost management in cloud databases to avoid unexpected bills and keep budgets under control.
💼 Career
Database administrators and cloud engineers often create cost tracking systems to monitor and optimize cloud resource usage.
Progress0 / 4 steps
1
DATA SETUP: Create the DynamoDB table
Create a DynamoDB table named DepartmentCosts with Department as the partition key (string) and Month as the sort key (string).
DynamoDB
Hint
Use dynamodb.create_table with KeySchema defining Department as HASH and Month as RANGE keys.
2
CONFIGURATION: Set the cost threshold
Create a variable called cost_threshold and set it to 1000 to represent the maximum allowed monthly cost in dollars.
DynamoDB
Hint
Just create a variable named cost_threshold and assign it the value 1000.
3
CORE LOGIC: Query departments exceeding the cost threshold
Write a query using the DynamoDB Table resource DepartmentCosts to find all items where the Month is '2024-05' and the Cost attribute is greater than cost_threshold. Use the variable expensive_departments to store the query result.
DynamoDB
Hint
Use DepartmentCosts.scan with a FilterExpression combining Key('Month').eq('2024-05') and Attr('Cost').gt(cost_threshold).
4
COMPLETION: Add a new cost entry for a department
Add a new item to the DepartmentCosts table with Department set to 'Marketing', Month set to '2024-05', and Cost set to 1200.
DynamoDB
Hint
Use DepartmentCosts.put_item with an Item dictionary containing the required keys and values.
Practice
(1/5)
1. Why is cost management important when using DynamoDB?
easy
A. It automatically increases your database capacity.
B. It helps avoid unexpected high bills by monitoring usage.
C. It guarantees 100% uptime for your database.
D. It encrypts your data for security.
Solution
Step 1: Understand the purpose of cost management
Cost management is about tracking and controlling how much you spend.
Step 2: Relate cost management to DynamoDB usage
By monitoring usage, you can avoid surprises in your bill.
Final Answer:
It helps avoid unexpected high bills by monitoring usage. -> Option B
Quick Check:
Cost management = Avoid surprises [OK]
Hint: Cost management = watch spending to avoid surprises [OK]