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
Table creation with AWS SDK
📖 Scenario: You are setting up a database table in AWS DynamoDB to store user information for a new web application.
🎯 Goal: Create a DynamoDB table named Users with a primary key UserId of type string using the AWS SDK.
📋 What You'll Learn
Create a variable called tableName with the value "Users".
Create a variable called keySchema defining the primary key with AttributeName as UserId and KeyType as HASH.
Create a variable called attributeDefinitions defining the attribute UserId with type S (string).
Create a variable called provisionedThroughput with ReadCapacityUnits and WriteCapacityUnits both set to 5.
Create a variable called params that combines all the above variables into a single object for table creation.
💡 Why This Matters
🌍 Real World
Creating DynamoDB tables is a common task when building serverless applications or cloud-native apps that need fast, scalable NoSQL databases.
💼 Career
Understanding how to configure and create DynamoDB tables using the AWS SDK is essential for cloud developers, DevOps engineers, and backend engineers working with AWS.
Progress0 / 4 steps
1
Create table name and key schema
Create a variable called tableName and set it to "Users". Then create a variable called keySchema as a list with one object that has AttributeName set to "UserId" and KeyType set to "HASH".
DynamoDB
Hint
Use const to declare variables. The keySchema is an array with one object describing the primary key.
2
Define attribute definitions
Create a variable called attributeDefinitions as a list with one object that has AttributeName set to "UserId" and AttributeType set to "S".
DynamoDB
Hint
The attributeDefinitions array describes the data type of each key attribute.
3
Set provisioned throughput
Create a variable called provisionedThroughput as an object with ReadCapacityUnits set to 5 and WriteCapacityUnits set to 5.
DynamoDB
Hint
Provisioned throughput sets how many reads and writes your table can handle per second.
4
Combine all into params object
Create a variable called params as an object that includes TableName set to tableName, KeySchema set to keySchema, AttributeDefinitions set to attributeDefinitions, and ProvisionedThroughput set to provisionedThroughput.
DynamoDB
Hint
The params object is what you pass to the AWS SDK to create the table.
Practice
(1/5)
1. What is the main purpose of specifying a primary key when creating a DynamoDB table using the AWS SDK?
easy
A. To set the table's read and write capacity
B. To specify the table's encryption settings
C. To define the table's region
D. To uniquely identify each item in the table
Solution
Step 1: Understand the role of a primary key in DynamoDB
The primary key uniquely identifies each item in the table, ensuring no duplicates.
Step 2: Differentiate from other table settings
Read/write capacity, region, and encryption are important but unrelated to item uniqueness.
Final Answer:
To uniquely identify each item in the table -> Option D
Quick Check:
Primary key = unique item ID [OK]
Hint: Primary key means unique ID for each item [OK]
Common Mistakes:
Confusing primary key with capacity settings
Thinking primary key sets region or encryption
Ignoring the uniqueness requirement
2. Which of the following is the correct way to specify the primary key attribute when creating a DynamoDB table using AWS SDK for JavaScript?
easy
A. "KeySchema": [{ "AttributeName": "UserId", "KeyType": "HASH" }]
B. "KeySchema": [{ "AttributeName": "UserId", "KeyType": "PRIMARY" }]
C. "KeySchema": [{ "AttributeName": "UserId", "KeyType": "PRIMARY_KEY" }]
D. "KeySchema": [{ "AttributeName": "UserId", "KeyType": "KEY" }]
Solution
Step 1: Recall AWS SDK syntax for KeySchema
The correct key type for the partition key is "HASH" in the KeySchema array.
Step 2: Identify incorrect key types
"PRIMARY", "PRIMARY_KEY", and "KEY" are not valid KeyType values in AWS SDK.
Final Answer:
"KeySchema": [{ "AttributeName": "UserId", "KeyType": "HASH" }] -> Option A
Quick Check:
KeyType for partition key = HASH [OK]
Hint: Use "HASH" for partition key in KeySchema [OK]
Common Mistakes:
Using invalid KeyType values like PRIMARY or KEY
Confusing KeyType with attribute types
Missing the array structure for KeySchema
3. Given the following AWS SDK code snippet for creating a DynamoDB table, what will be the output if the table creation is successful?
Step 1: Check KeySchema and AttributeDefinitions consistency
Both "OrderId" and "OrderDate" are in KeySchema, but only "OrderId" is defined in AttributeDefinitions.
Step 2: Identify missing attribute definition
"OrderDate" must be defined in AttributeDefinitions to avoid error.
Final Answer:
Missing AttributeDefinition for "OrderDate" -> Option B
Quick Check:
All key attributes need AttributeDefinitions [OK]
Hint: Define all key attributes in AttributeDefinitions [OK]
Common Mistakes:
Forgetting to define all key attributes
Assuming RANGE is invalid KeyType
Blaming ProvisionedThroughput or TableName
5. You want to create a DynamoDB table named "Employees" with a composite primary key consisting of "EmployeeId" (string) as the partition key and "Department" (string) as the sort key. You also want to set the read capacity to 3 and write capacity to 2. Which of the following AWS SDK parameter objects correctly creates this table?