An online learning platform stores student registration records in an Amazon DynamoDB table. The table uses StudentID as the partition key. A new feature requires retrieving a list of all students who registered in the last days. Registration dates are stored in an attribute named RegistrationDate. Which approach should the developer use to retrieve these records with the lowest latency and minimal Read Capacity Unit (RCU) consumption?
- Create a Global Secondary Index (GSI) with RegistrationDate as the partition key, and perform a Query operation on the GSI.Answer
- BPerform a Scan operation on the base table using a FilterExpression on RegistrationDate.
- CPerform a Scan operation on the base table, and double the provisioned Read Capacity Units (RCUs) to prevent ProvisionedThroughputExceededException errors.
- DInitialize the AWS SDK DynamoDB client using hardcoded AWS access keys in the application code, and perform a Scan operation.
Answer
Create a Global Secondary Index (GSI) with RegistrationDate as the partition key, and perform a Query operation on the GSI.
Creating a Global Secondary Index (GSI) with RegistrationDate as the partition key enables the application to use the Query operation. A Query operation targets only the items within the specified partition key value, significantly reducing latency and RCU consumption compared to scanning the entire table.
Step-by-Step Solution
Key Concept
Using Global Secondary Indexes (GSIs) and the Query operation instead of a Scan operation to retrieve data efficiently based on non-key attributes.