📖 Scenario: You are working on a cloud project where you need to store user data in a fast and scalable database. Amazon DynamoDB is a great choice because it is a managed NoSQL database service that can handle large amounts of data with low latency.In this project, you will create a DynamoDB table step-by-step using AWS CloudFormation syntax. This will help you understand how to define cloud infrastructure as code.
🎯 Goal: Create a DynamoDB table named UserData with a primary key called UserId of type string. You will define the table structure, add a provisioned throughput configuration, and complete the CloudFormation resource definition.
📋 What You'll Learn
Create a CloudFormation resource for a DynamoDB table named UserData
Define the primary key attribute UserId as a string
Set the provisioned throughput with read capacity units 5 and write capacity units 5
Complete the CloudFormation resource with all required properties
💡 Why This Matters
🌍 Real World
DynamoDB tables are widely used in cloud applications to store user profiles, session data, and other fast-access information.
💼 Career
Understanding how to define DynamoDB tables in infrastructure as code is essential for cloud engineers and developers working with AWS.
Progress0 / 4 steps
1
Define the DynamoDB table resource
Create a CloudFormation resource named UserData of type AWS::DynamoDB::Table. Inside it, add the Properties key with an empty dictionary. This will be the base for your DynamoDB table definition.
AWS
Hint
Start by defining the resource name UserData and set its type to AWS::DynamoDB::Table. Add an empty Properties block.
2
Add the primary key attribute
Inside the Properties of UserData, add the AttributeDefinitions list with one item. This item should have AttributeName set to UserId and AttributeType set to S (string). Also add the KeySchema list with one item where AttributeName is UserId and KeyType is HASH.
AWS
Hint
Define the attribute UserId as a string in AttributeDefinitions. Then set it as the partition key in KeySchema with KeyType HASH.
3
Add provisioned throughput configuration
Inside the Properties of UserData, add the ProvisionedThroughput key. Set ReadCapacityUnits to 5 and WriteCapacityUnits to 5. This configures the read and write capacity for the table.
AWS
Hint
Add ProvisionedThroughput with ReadCapacityUnits and WriteCapacityUnits both set to 5.
4
Complete the DynamoDB table resource
Ensure the CloudFormation resource UserData includes Type as AWS::DynamoDB::Table and Properties with AttributeDefinitions, KeySchema, and ProvisionedThroughput exactly as specified. This completes the DynamoDB table definition.
AWS
Hint
Check that the resource UserData has all required properties correctly defined.
Practice
(1/5)
1. What is the main purpose of the primary key when creating a DynamoDB table?
easy
A. To define the table's read capacity
B. To store the table's name
C. To specify the AWS region
D. To uniquely identify each item in the table
Solution
Step 1: Understand the role of the primary key
The primary key uniquely identifies each item in a DynamoDB table, ensuring no duplicates.
Step 2: Differentiate from other table properties
Table name, capacity, and region do not serve as unique identifiers for items.
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 table name
Thinking capacity defines uniqueness
Mixing region with key attributes
2. Which AWS CLI command correctly creates a DynamoDB table named Users with a primary key UserId of type string?
But you get an error. What is the most likely cause?
medium
A. The attribute definition and key schema attribute names do not match
B. Provisioned throughput values are missing
C. The key schema is missing a RANGE key
D. AttributeType should be 'S' for string, not 'N' for number
Solution
Step 1: Check attribute definitions and key schema names
The attribute definitions specify AttributeName=Id, but the key schema specifies AttributeName=OrderId. The names do not match, causing the error.
Step 2: Verify other potential issues
Provisioned throughput values are present (not B), a simple primary key with only HASH is allowed (not C), AttributeType=N is valid for numeric IDs (not D).
Final Answer:
The attribute definition and key schema attribute names do not match -> Option A
Quick Check:
Attribute names must match exactly [OK]
Hint: Match attribute names exactly in definitions and key schema [OK]
Common Mistakes:
Assuming 'N' type is invalid
Expecting RANGE key for all tables
Missing provisioned throughput
5. You want to create a DynamoDB table named Sessions with a composite primary key: UserId (string) as HASH and SessionId (string) as RANGE. You also want to set autoscaling for read and write capacity. Which of the following is the best approach?
hard
A. Create the table without specifying key schema and add keys later
B. Use aws dynamodb create-table with attribute definitions and key schema, then configure autoscaling via Application Auto Scaling service
C. Use aws dynamodb create-table with only HASH key and enable autoscaling in the same command
D. Create the table with fixed provisioned throughput and manually update capacity when needed
Solution
Step 1: Define table with composite primary key
Use create-table with attribute definitions for UserId and SessionId, and key schema with HASH and RANGE keys.
Step 2: Configure autoscaling separately
DynamoDB autoscaling is set up via Application Auto Scaling service after table creation; it cannot be enabled directly in create-table command.
Final Answer:
Use aws dynamodb create-table with attribute definitions and key schema, then configure autoscaling via Application Auto Scaling service -> Option B
Quick Check:
Composite key + separate autoscaling setup = Use aws dynamodb create-table with attribute definitions and key schema, then configure autoscaling via Application Auto Scaling service [OK]
Hint: Create table first, then set autoscaling separately [OK]
Common Mistakes:
Trying to enable autoscaling in create-table command
Skipping RANGE key for composite key
Creating table without key schema
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.