A developer is building a blogging application where posts are stored in an Amazon DynamoDB table. The table's partition key is AuthorId and the sort key is PostId. The application needs to retrieve all posts written by a specific author that were published within the last 30 days. This operation must minimize latency and read capacity unit (RCU) consumption. Which combination of actions should the developer take to meet these requirements? (Select TWO.)
- Create a Global Secondary Index (GSI) with AuthorId as the partition key and PublishDate as the sort key.Answer
- Perform a Query operation on the Global Secondary Index (GSI) using a KeyConditionExpression to specify the AuthorId and PublishDate range.Answer
- CPerform a Scan operation on the base table using a FilterExpression to filter by AuthorId and PublishDate.
- DPerform a Query operation on the base table using a FilterExpression for both AuthorId and PublishDate.
- EInitialize the Amazon DynamoDB client by hardcoding the AWS access keys in the application source code.
Answer
To optimize the retrieval, the developer should create a Global Secondary Index (GSI) with AuthorId as the partition key and PublishDate as the sort key, and then perform a Query operation on that GSI using a KeyConditionExpression for both fields.
To optimize read capacity unit (RCU) consumption and reduce latency, the query should target only the relevant data. Creating a Global Secondary Index (GSI) with AuthorId as the partition key and PublishDate as the sort key enables querying by date. Querying the GSI using a KeyConditionExpression for both AuthorId and PublishDate ensures that DynamoDB reads only the items that match the criteria.
Step-by-Step Solution
Key Concept
Using a Global Secondary Index (GSI) with a KeyConditionExpression to optimize queries on non-primary key attributes and minimize RCU consumption.