Complete the code to specify the primary key for a DynamoDB table.
KeySchema: [{ AttributeName: 'UserId', KeyType: '[1]' }]The primary key's partition key in DynamoDB is defined with KeyType 'HASH'. This determines how data is distributed.
Complete the code to add a sort key to the DynamoDB table design.
KeySchema: [ { AttributeName: 'UserId', KeyType: 'HASH' }, { AttributeName: 'Timestamp', KeyType: '[1]' } ]The sort key in DynamoDB is defined with KeyType 'RANGE'. It allows sorting and querying within the partition.
Fix the error in the attribute definition for the partition key.
AttributeDefinitions: [ { AttributeName: 'UserId', AttributeType: '[1]' } ]The partition key attribute type is usually a string, represented by 'S' in DynamoDB.
Fill both blanks to create a Global Secondary Index (GSI) with a partition and sort key.
GlobalSecondaryIndexes: [{ IndexName: 'StatusIndex', KeySchema: [ { AttributeName: '[1]', KeyType: 'HASH' }, { AttributeName: '[2]', KeyType: 'RANGE' } ], Projection: { ProjectionType: 'ALL' } }]The GSI uses 'Status' as the partition key and 'CreatedAt' as the sort key to allow queries by status and time.
Fill all three blanks to create a DynamoDB query filtering items by partition key and a condition on the sort key.
const params = { TableName: 'Orders', KeyConditionExpression: '#pk = :pkVal AND [1] [2] :sortVal', ExpressionAttributeNames: { '#pk': '[3]' }, ExpressionAttributeValues: { ':pkVal': '123', ':sortVal': 20230101 } };The query filters items where the partition key 'OrderId' equals '123' and the sort key 'Timestamp' is greater than a given value.