Bird
Raised Fist0
DynamoDBquery~10 mins

AWS Console and DynamoDB setup - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

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
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a DynamoDB table with a primary key named 'UserId'.

DynamoDB
aws dynamodb create-table --table-name Users --attribute-definitions AttributeName=UserId,AttributeType=S --key-schema AttributeName=[1],KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
Drag options to blanks, or click blank then click option'
AUsername
BUserId
CEmail
DId
Attempts:
3 left
💡 Hint
Common Mistakes
Using a key name not defined in attribute definitions
Mismatching attribute names
2fill in blank
medium

Complete the code to add a Global Secondary Index named 'EmailIndex' with 'Email' as the partition key.

DynamoDB
aws dynamodb update-table --table-name Users --attribute-definitions AttributeName=Email,AttributeType=S --global-secondary-index-updates '[{"Create":{"IndexName":"EmailIndex","KeySchema":[{"AttributeName":"[1]","KeyType":"HASH"}],"Projection":{"ProjectionType":"ALL"},"ProvisionedThroughput":{"ReadCapacityUnits":5,"WriteCapacityUnits":5}}}]'
Drag options to blanks, or click blank then click option'
AUserId
BId
CEmail
DUsername
Attempts:
3 left
💡 Hint
Common Mistakes
Using the table's primary key instead of the index key
Mismatching attribute names in KeySchema
3fill in blank
hard

Fix the error in the command to delete the DynamoDB table named 'Users'.

DynamoDB
aws dynamodb [1] --table-name Users
Drag options to blanks, or click blank then click option'
Adelete-table
Bremove-table
Cdrop-table
Ddestroy-table
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent commands like 'remove-table' or 'drop-table'
4fill in blank
hard

Fill both blanks to create a DynamoDB table with a composite primary key: 'UserId' as partition key and 'Timestamp' as sort key.

DynamoDB
aws dynamodb create-table --table-name UserActivity --attribute-definitions AttributeName=[1],AttributeType=S AttributeName=[2],AttributeType=N --key-schema AttributeName=UserId,KeyType=HASH AttributeName=Timestamp,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
Drag options to blanks, or click blank then click option'
AUserId
BTimestamp
CActivity
DDate
Attempts:
3 left
💡 Hint
Common Mistakes
Missing attribute definitions for sort key
Using wrong attribute names
5fill in blank
hard

Fill all three blanks to write a command that puts an item with 'UserId', 'Timestamp', and 'Activity' attributes into the 'UserActivity' table.

DynamoDB
aws dynamodb put-item --table-name UserActivity --item '{"UserId": {"S": "[1]"}, "Timestamp": {"N": "[2]"}, "Activity": {"S": "[3]"}}'
Drag options to blanks, or click blank then click option'
Auser123
B1680000000
CLogin
DLogout
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong data types for attributes
Mismatching attribute names

Practice

(1/5)
1. What is the main purpose of the primary key when creating a DynamoDB table in the AWS Console?
easy
A. To uniquely identify each item in the table
B. To set the read and write capacity
C. To define the table's region
D. To specify the encryption method

Solution

  1. Step 1: Understand the role of the primary key

    The primary key is used to uniquely identify each item in a DynamoDB table, ensuring no duplicates.
  2. Step 2: Compare with other options

    Read/write capacity, region, and encryption are important but unrelated to item uniqueness.
  3. Final Answer:

    To uniquely identify each item in the table -> Option A
  4. Quick Check:

    Primary key = unique item ID [OK]
Hint: Primary key always means unique ID for each item [OK]
Common Mistakes:
  • Confusing primary key with capacity settings
  • Thinking primary key sets table region
  • Assuming primary key controls encryption
2. Which of the following is the correct way to select the capacity mode when creating a DynamoDB table in the AWS Console?
easy
A. Set capacity mode to Manual or Automatic
B. Choose between On-Demand or Provisioned capacity modes
C. Select capacity mode as Static or Dynamic
D. Pick capacity mode as Fixed or Variable

Solution

  1. Step 1: Recall DynamoDB capacity modes

    DynamoDB offers two capacity modes: On-Demand (automatic scaling) and Provisioned (fixed capacity).
  2. Step 2: Eliminate incorrect terms

    Manual/Automatic, Static/Dynamic, Fixed/Variable are not official DynamoDB terms for capacity modes.
  3. Final Answer:

    Choose between On-Demand or Provisioned capacity modes -> Option B
  4. Quick Check:

    Capacity mode = On-Demand or Provisioned [OK]
Hint: Remember only On-Demand and Provisioned are valid capacity modes [OK]
Common Mistakes:
  • Using wrong terms like Manual or Static
  • Confusing capacity mode with encryption settings
  • Assuming capacity mode is set after table creation
3. You create a DynamoDB table with a primary key named OrderId and choose On-Demand capacity mode. What happens when you insert a new item with OrderId = 123?
medium
A. The table requires manual capacity increase before insertion
B. The item is rejected because capacity is not provisioned
C. The item is stored uniquely and capacity scales automatically
D. The item overwrites any existing item regardless of key

Solution

  1. Step 1: Understand On-Demand capacity mode behavior

    On-Demand mode automatically adjusts capacity to handle requests without manual provisioning.
  2. Step 2: Consider primary key uniqueness

    Primary key OrderId ensures the item with value 123 is stored uniquely; no overwriting unless key duplicates.
  3. Final Answer:

    The item is stored uniquely and capacity scales automatically -> Option C
  4. Quick Check:

    On-Demand + unique key = auto scale and store [OK]
Hint: On-Demand means no manual capacity needed [OK]
Common Mistakes:
  • Thinking On-Demand requires manual capacity setup
  • Assuming item overwrites existing without key conflict
  • Believing insertion fails without provisioned capacity
4. You tried to create a DynamoDB table in the AWS Console but got an error saying the primary key is missing. What should you do to fix this?
medium
A. Create the table without a primary key and add it later
B. Skip primary key and rely on DynamoDB to auto-generate it
C. Set the capacity mode to Provisioned to avoid the error
D. Specify a primary key attribute name and type before creating the table

Solution

  1. Step 1: Recognize primary key requirement

    DynamoDB requires a primary key defined at table creation to uniquely identify items.
  2. Step 2: Correct the table setup

    Specify the primary key attribute name (e.g., "UserId") and its data type (String or Number) in the AWS Console before creating the table.
  3. Final Answer:

    Specify a primary key attribute name and type before creating the table -> Option D
  4. Quick Check:

    Primary key must be set at creation [OK]
Hint: Always define primary key before creating table [OK]
Common Mistakes:
  • Expecting DynamoDB to auto-create primary key
  • Trying to create table without primary key
  • Changing capacity mode to fix primary key error
5. You want to create a DynamoDB table for a mobile app that has unpredictable traffic spikes. Which capacity mode should you choose in the AWS Console to optimize cost and performance?
hard
A. On-Demand capacity mode to handle variable traffic automatically
B. Provisioned capacity mode with fixed read/write units
C. Provisioned capacity mode with auto-scaling disabled
D. Manual capacity mode with scheduled scaling

Solution

  1. Step 1: Analyze traffic pattern

    Unpredictable traffic spikes require flexible capacity to avoid throttling or overspending.
  2. Step 2: Choose capacity mode accordingly

    On-Demand capacity mode automatically adjusts to traffic changes, optimizing cost and performance without manual intervention.
  3. Step 3: Eliminate incorrect options

    Provisioned with fixed units or disabled auto-scaling cannot handle spikes well; manual mode is not a DynamoDB option.
  4. Final Answer:

    On-Demand capacity mode to handle variable traffic automatically -> Option A
  5. Quick Check:

    Unpredictable traffic = On-Demand mode [OK]
Hint: Use On-Demand for apps with unpredictable traffic [OK]
Common Mistakes:
  • Choosing fixed provisioned capacity for variable traffic
  • Disabling auto-scaling in provisioned mode
  • Assuming manual capacity mode exists