Complete the code to define the partition key for a GSI in DynamoDB.
KeySchema: [{ AttributeName: '[1]', KeyType: 'HASH' }]The partition key for a GSI should be an attribute that evenly distributes data. 'UserId' is a common choice.
Complete the code to define the sort key for a GSI in DynamoDB.
KeySchema: [ { AttributeName: 'UserId', KeyType: 'HASH' }, { AttributeName: '[1]', KeyType: 'RANGE' } ]The sort key (RANGE) organizes data within the partition. 'OrderId' is a good choice to sort user orders.
Fix the error in the GSI attribute definitions by selecting the correct attribute type.
AttributeDefinitions: [ { AttributeName: 'UserId', AttributeType: '[1]' }, { AttributeName: 'OrderDate', AttributeType: 'S' } ]'UserId' is usually a string, so its attribute type should be 'S' for string.
Fill both blanks to create a GSI that uses 'Status' as partition key and 'CreatedAt' as 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 organize items by status and creation time.
Fill all three blanks to define a GSI with keys and projection type.
GlobalSecondaryIndexes: [{ IndexName: 'EmailIndex', KeySchema: [ { AttributeName: '[1]', KeyType: 'HASH' }, { AttributeName: '[2]', KeyType: 'RANGE' } ], Projection: { ProjectionType: '[3]' } }]This GSI uses 'Email' as partition key, 'SignupDate' as sort key, and projects all attributes.