Complete the code to specify the sort key attribute name in a DynamoDB table creation.
KeySchema=[{'AttributeName': 'UserId', 'KeyType': 'HASH'}, {'AttributeName': '[1]', 'KeyType': 'RANGE'}]The sort key is often used to sort items with the same partition key. 'Timestamp' is a common choice for a sort key.
Complete the query to get all items with a specific partition key and sort key greater than a value.
KeyConditionExpression = Key('UserId').eq('user123') & Key('Timestamp').[1]('2023-01-01T00:00:00Z')
The 'gt' operator means 'greater than', which filters items with sort key values after the given timestamp.
Fix the error in the query condition to correctly filter items by sort key prefix.
KeyConditionExpression = Key('UserId').eq('user123') & Key('Timestamp').[1]('2023-01')
The 'begins_with' function filters items where the sort key starts with the given prefix, useful for date prefixes.
Fill both blanks to create a DynamoDB table with a partition key 'OrderId' and a sort key 'OrderDate'.
AttributeDefinitions=[{'AttributeName': '[1]', 'AttributeType': 'S'}, {'AttributeName': '[2]', 'AttributeType': 'S'}]Both 'OrderId' and 'OrderDate' must be defined as attributes with type 'S' (string) before using them as keys.
Fill all three blanks to query items with partition key 'ProductId', sort key greater than '2023-01-01', and project only 'Price' and 'Stock'.
response = table.query(KeyConditionExpression=Key('[1]').eq('prod123') & Key('[2]').[3]('2023-01-01'), ProjectionExpression='Price, Stock')
'ProductId' is the partition key, 'CreatedAt' is the sort key attribute, and 'gt' filters items with sort key values greater than the date.