Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Create Your First DynamoDB Table
📖 Scenario: You are setting up a simple database table to store information about books in a library. Each book has a unique ID and a title.
🎯 Goal: Create a DynamoDB table named Books with a primary key called BookID of type string.
📋 What You'll Learn
Create a table named Books
Use BookID as the partition key
Set the partition key type to S (string)
Set the read and write capacity units to 5
💡 Why This Matters
🌍 Real World
Creating DynamoDB tables is a common task when setting up cloud databases for applications like online stores, mobile apps, or IoT devices.
💼 Career
Knowing how to create and configure DynamoDB tables is essential for cloud developers, database administrators, and backend engineers working with AWS.
Progress0 / 4 steps
1
Define the table name and key schema
Create a variable called table_name and set it to 'Books'. Then create a variable called key_schema that defines the partition key with AttributeName as 'BookID' and KeyType as 'HASH'.
DynamoDB
Hint
Remember, the partition key is called BookID and its key type is HASH.
2
Define the attribute definitions and provisioned throughput
Create a variable called attribute_definitions that defines BookID as type 'S'. Then create a variable called provisioned_throughput with ReadCapacityUnits and WriteCapacityUnits both set to 5.
DynamoDB
Hint
Attribute type 'S' means string. Set both read and write capacity units to 5.
3
Create the table creation parameters dictionary
Create a variable called table_params that combines table_name, key_schema, attribute_definitions, and provisioned_throughput into one dictionary with keys TableName, KeySchema, AttributeDefinitions, and ProvisionedThroughput respectively.
DynamoDB
Hint
Combine all parts into one dictionary called table_params.
4
Add the final command to create the DynamoDB table
Create a variable called dynamodb_client that represents the DynamoDB client. Then create a variable called create_table_response that calls dynamodb_client.create_table() with table_params as the argument.
DynamoDB
Hint
Use boto3.client('dynamodb') to create the client and call create_table() with the parameters.
Practice
(1/5)
1. What is the minimum required element when creating a DynamoDB table?
easy
A. Table name and global secondary index
B. Table name and secondary index
C. Table name and primary key
D. Provisioned throughput only
Solution
Step 1: Understand DynamoDB table basics
Every DynamoDB table must have a unique name and a primary key to identify items.
Step 2: Identify required elements for creation
Secondary indexes and throughput settings are optional or have defaults, but primary key and table name are mandatory.
Final Answer:
Table name and primary key -> Option C
Quick Check:
Minimum required = Table name + primary key [OK]
Hint: Always specify table name and primary key first [OK]
Common Mistakes:
Forgetting to define the primary key
Confusing secondary index as mandatory
Omitting the table name
2. Which AWS CLI command correctly creates a DynamoDB table named Users with a primary key UserId of type string?
The attribute-definitions must include AttributeType (S, N, or B). Here, AttributeType is missing.
Step 2: Verify other parts
KeyType is present, throughput values are valid, and table name is valid. So the error is due to missing AttributeType.
Final Answer:
Missing AttributeType in attribute-definitions -> Option B
Quick Check:
AttributeType required in attribute-definitions [OK]
Hint: Always specify AttributeType with AttributeName [OK]
Common Mistakes:
Omitting AttributeType in attribute-definitions
Confusing KeyType with AttributeType
Assuming throughput values cause error
5. You want to create a DynamoDB table named Employees with a composite primary key: EmployeeId (string) as partition key and Department (string) as sort key. Which command correctly creates this table?