0
0
DynamoDBquery~10 mins

Sort key purpose and usage in DynamoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the sort key attribute name in a DynamoDB table creation.

DynamoDB
KeySchema=[{'AttributeName': 'UserId', 'KeyType': 'HASH'}, {'AttributeName': '[1]', 'KeyType': 'RANGE'}]
Drag options to blanks, or click blank then click option'
AUserId
BStatus
CTimestamp
DEmail
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same attribute name for both partition and sort keys.
Choosing an attribute that does not help sort the data.
2fill in blank
medium

Complete the query to get all items with a specific partition key and sort key greater than a value.

DynamoDB
KeyConditionExpression = Key('UserId').eq('user123') & Key('Timestamp').[1]('2023-01-01T00:00:00Z')
Drag options to blanks, or click blank then click option'
Alt
Bgt
Ceq
Dbegins_with
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lt' which means less than.
Using 'eq' which means equal to only.
3fill in blank
hard

Fix the error in the query condition to correctly filter items by sort key prefix.

DynamoDB
KeyConditionExpression = Key('UserId').eq('user123') & Key('Timestamp').[1]('2023-01')
Drag options to blanks, or click blank then click option'
Agt
Beq
Clt
Dbegins_with
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'eq' which requires exact match.
Using 'gt' or 'lt' which compare full values, not prefixes.
4fill in blank
hard

Fill both blanks to create a DynamoDB table with a partition key 'OrderId' and a sort key 'OrderDate'.

DynamoDB
AttributeDefinitions=[{'AttributeName': '[1]', 'AttributeType': 'S'}, {'AttributeName': '[2]', 'AttributeType': 'S'}]
Drag options to blanks, or click blank then click option'
AOrderId
BOrderDate
CCustomerId
DStatus
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing attribute names that are not keys.
Not defining both keys in AttributeDefinitions.
5fill in blank
hard

Fill all three blanks to query items with partition key 'ProductId', sort key greater than '2023-01-01', and project only 'Price' and 'Stock'.

DynamoDB
response = table.query(KeyConditionExpression=Key('[1]').eq('prod123') & Key('[2]').[3]('2023-01-01'), ProjectionExpression='Price, Stock')
Drag options to blanks, or click blank then click option'
AProductId
BTimestamp
Cgt
DCreatedAt
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute names for keys.
Using 'eq' instead of 'gt' for filtering sort key.