0
0
DynamoDBquery~20 mins

Identifying access patterns first in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Access Pattern Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Query Result for Single Partition Key Access

You have a DynamoDB table with PartitionKey as the primary key. You run this query to get all items with PartitionKey = 'User#123'. What will be the output?

DynamoDB
SELECT * FROM Table WHERE PartitionKey = 'User#123';
AOnly one item with PartitionKey 'User#123' will be returned, even if multiple exist.
BAll items with PartitionKey 'User#123' will be returned.
CQuery will fail because PartitionKey must be unique.
DNo items will be returned unless SortKey is specified.
Attempts:
2 left
💡 Hint

Think about how DynamoDB handles queries on partition keys.

🧠 Conceptual
intermediate
2:00remaining
Choosing Partition Key for Efficient Access

You want to design a DynamoDB table to store orders. You expect frequent queries by CustomerID and occasional queries by OrderDate. Which is the best choice for the partition key to optimize access patterns?

AUse <code>OrderDate</code> as the partition key.
BUse a composite key with <code>OrderDate</code> as partition key and <code>CustomerID</code> as sort key.
CUse a random UUID as the partition key.
DUse <code>CustomerID</code> as the partition key.
Attempts:
2 left
💡 Hint

Think about which attribute is used most often in queries.

📝 Syntax
advanced
2:00remaining
Identify the Correct DynamoDB Query Syntax

Which of the following DynamoDB query expressions correctly retrieves items with PartitionKey = 'User#456' and SortKey starting with 'Order#'?

DynamoDB
Assume table has PartitionKey and SortKey attributes.
AQueryInput={ TableName: 'Table', KeyConditionExpression: 'PartitionKey = :pk and begins_with(SortKey, :sk)', ExpressionAttributeValues: { ':pk': 'User#456', ':sk': 'Order#' } }
BQueryInput={ TableName: 'Table', KeyConditionExpression: 'PartitionKey = :pk and SortKey = :sk', ExpressionAttributeValues: { ':pk': 'User#456', ':sk': 'Order#' } }
CQueryInput={ TableName: 'Table', FilterExpression: 'begins_with(SortKey, :sk)', ExpressionAttributeValues: { ':sk': 'Order#' } }
DQueryInput={ TableName: 'Table', KeyConditionExpression: 'PartitionKey = :pk or begins_with(SortKey, :sk)', ExpressionAttributeValues: { ':pk': 'User#456', ':sk': 'Order#' } }
Attempts:
2 left
💡 Hint

Remember that KeyConditionExpression must use AND and can use begins_with for sort keys.

optimization
advanced
2:00remaining
Optimizing Access Patterns with Secondary Indexes

You have a DynamoDB table with primary key CustomerID and OrderID. You want to efficiently query orders by OrderStatus. What is the best way to optimize this access pattern?

AUse a Scan operation filtering by <code>OrderStatus</code>.
BAdd <code>OrderStatus</code> as a sort key to the primary key.
CCreate a Global Secondary Index (GSI) with <code>OrderStatus</code> as partition key.
DStore <code>OrderStatus</code> in a separate table.
Attempts:
2 left
💡 Hint

Think about how to query efficiently by an attribute not in the primary key.

🔧 Debug
expert
3:00remaining
Debugging a Query Returning No Results

You run this DynamoDB query to get all orders for CustomerID = 'Cust#789' with OrderDate after '2023-01-01'. The query returns no results, but you know matching items exist. What is the likely cause?

QueryInput={
  TableName: 'Orders',
  KeyConditionExpression: 'CustomerID = :cid and OrderDate > :date',
  ExpressionAttributeValues: { ':cid': 'Cust#789', ':date': '2023-01-01' }
}
AOrderDate is not part of the primary key or sort key, so it cannot be used in KeyConditionExpression.
BThe date format '2023-01-01' is invalid for DynamoDB queries.
CCustomerID value is case-sensitive and 'Cust#789' does not match stored keys.
DExpressionAttributeValues keys must be prefixed with a hash (#) symbol.
Attempts:
2 left
💡 Hint

Check which attributes can be used in KeyConditionExpression.