0
0
DynamoDBquery~20 mins

Key condition expressions in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Key Condition Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Query with simple partition key condition
Given a DynamoDB table named Orders with OrderID as the partition key, what will be the output of this key condition expression?

OrderID = :orderId

Assuming :orderId is set to 12345 and the table contains one item with OrderID 12345 and CustomerName 'Alice'.
DynamoDB
KeyConditionExpression: 'OrderID = :orderId',
ExpressionAttributeValues: { ':orderId': { N: '12345' } }
AReturns all items because partition key is ignored in key condition.
BReturns items with OrderID greater than 12345.
CReturns the item with OrderID 12345 and CustomerName 'Alice'.
DReturns no items because the key condition syntax is invalid.
Attempts:
2 left
💡 Hint
Remember, the key condition expression must specify the partition key equality.
query_result
intermediate
2:00remaining
Using sort key with BETWEEN in key condition
Consider a DynamoDB table Events with UserID as partition key and EventDate as sort key (string in 'YYYY-MM-DD' format). What will this key condition expression return?

UserID = :uid AND EventDate BETWEEN :start AND :end

With values:
:uid = 'user1'
:start = '2023-01-01'
:end = '2023-01-31'

The table has events for user1 on '2023-01-10', '2023-02-01', and '2023-01-20'.
DynamoDB
KeyConditionExpression: 'UserID = :uid AND EventDate BETWEEN :start AND :end',
ExpressionAttributeValues: { ':uid': { S: 'user1' }, ':start': { S: '2023-01-01' }, ':end': { S: '2023-01-31' } }
AReturns events on '2023-01-10' and '2023-01-20' for user1.
BReturns all events for user1 regardless of date.
CReturns only the event on '2023-02-01' for user1.
DReturns no events because BETWEEN is not valid in key condition.
Attempts:
2 left
💡 Hint
BETWEEN works on sort keys to filter a range of values.
📝 Syntax
advanced
2:00remaining
Identify syntax error in key condition expression
Which option contains a syntax error in the DynamoDB key condition expression?
AUserID = :uid AND begins_with(EventDate, :prefix)
BUserID = :uid OR EventDate = :date
CUserID = :uid AND EventDate > :date
DUserID = :uid AND EventDate BETWEEN :start AND :end
Attempts:
2 left
💡 Hint
Key condition expressions only allow AND, not OR.
query_result
advanced
2:00remaining
Effect of missing partition key in key condition
What happens if you run a DynamoDB query with this key condition expression?

EventDate = :date

Given that EventDate is the sort key and UserID is the partition key.
DynamoDB
KeyConditionExpression: 'EventDate = :date',
ExpressionAttributeValues: { ':date': { S: '2023-01-01' } }
AQuery returns all items with EventDate '2023-01-01' across all users.
BQuery returns all items in the table.
CQuery returns no items because sort key alone cannot be used.
DQuery fails with an error because partition key is missing.
Attempts:
2 left
💡 Hint
Partition key equality is mandatory in key condition expressions.
🧠 Conceptual
expert
2:00remaining
Understanding key condition expression limitations
Which statement correctly describes a limitation of DynamoDB key condition expressions?
AKey condition expressions must include the partition key with equality and can optionally include sort key conditions.
BKey condition expressions can filter on any attribute, including non-key attributes.
CKey condition expressions support OR operators to combine multiple conditions.
DKey condition expressions can use any comparison operator on the partition key.
Attempts:
2 left
💡 Hint
Think about what is mandatory and optional in key condition expressions.