AWS Certified Developer – Associate — Question 269
A calendar application gives users the ability to schedule and share events. The application stores its data in several Amazon DynamoDB tables. The Events table stores all events for the application. The Events table has a primary key in which the partition key is the date of the event and the sort key is the user’s unique ID number.
A developer is working on a dashboard that will show each user all the details for all their events scheduled on a single day. The developer needs to get the data from the Events table.
What should the developer do to get the relevant data MOST efficiently?
Answer options
- A. Perform a scan on the Events table by using the partition key and the sort key as filter expressions.
- B. Perform a query on the Events table by using the partition key and the sort key as filter expressions.
- C. Perform a scan on the Events table by using the partition key and the sort key in a key condition expression.
- D. Perform a query on the Events table by using the partition key and the sort key in a key condition expression.
Correct answer: D
Explanation
Performing a Query operation is significantly more efficient than a Scan because it directly targets the specific partition key instead of searching the entire table. By specifying both the partition key (date) and sort key (user ID) in a key condition expression, DynamoDB can retrieve the exact item directly. Using filter expressions or attempting to use key condition expressions on a Scan operation is either highly inefficient or syntactically invalid.