A developer is implementing a news publishing application that stores article metadata in an Amazon DynamoDB table. The base table uses `ArticleID` as the partition key and `Category` as the sort key. The application needs to frequently retrieve all articles written by a specific author, sorted by their publication date, to display on the author's biography page. The author's identifier is stored in an attribute named `AuthorID`, and the publication date is stored in `PublishDate`.
Which approach should the developer implement to retrieve this data in the most cost-effective and performant manner?
- Create a Global Secondary Index (GSI) with AuthorID as the partition key and PublishDate as the sort key, then use the Query API operation on the GSI.Answer
- BPerform a Scan API operation on the base table using a FilterExpression to filter results by AuthorID and PublishDate.
- CIncrease the provisioned read capacity units (RCUs) on the base table and perform a full scan to prevent performance degradation.
- DInitialize the AWS SDK client using hardcoded IAM access keys to bypass read capacity limits and access the table partitions directly.
Answer
Create a Global Secondary Index (GSI) with AuthorID as the partition key and PublishDate as the sort key, then use the Query API operation on the GSI.
Creating a Global Secondary Index (GSI) with AuthorID as the partition key and PublishDate as the sort key enables the application to perform highly efficient Query operations. Since a Query operation only reads the items that match the specified partition key value, this approach minimizes Read Capacity Unit (RCU) consumption and retrieval latency.
Step-by-Step Solution
Key Concept
Efficient data retrieval in DynamoDB using Global Secondary Indexes (GSIs) and the Query API operation to avoid expensive Scan operations.