How to query DynamoDB with same partition key and different sort key?
A developer is writing an application, which stores data in an Amazon DynamoDB table. The developer wants to query the DynamoDB table by using the partition key and a different sort key value. The developer needs the latest data with all recent write operations. How should the developer write the DynamoDB query?
Community Votes
82% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
This question tests the distinction between LSI and GSI partition key requirements, as well as the difference between eventually and strongly consistent reads in DynamoDB.
To query a DynamoDB table using the same partition key but a different sort key, a Local Secondary Index (LSI) is required. For the latest data with all recent writes, strongly consistent reads must be used.
Many candidates choose D (GSI with strongly consistent reads) because they confuse GSI and LSI, or forget that GSIs do not support strongly consistent reads.
Community Discussion (5 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Understanding the Requirements
The question has two distinct requirements:
1. Query using the same partition key but a different sort key value. 2. Retrieve the latest data with all recent write operations.
Why a Local Secondary Index (LSI) is Required
A Local Secondary Index (LSI) in DynamoDB allows you to create an alternate sort key while keeping the same partition key as the base table. This is exactly what the developer needs. An LSI must be created at the time of table creation and cannot be added later.
In contrast, a Global Secondary Index (GSI) allows both a different partition key and a different sort key. Since the developer wants to keep the same partition key, an LSI is the correct choice.
Why Strongly Consistent Reads are Required
DynamoDB offers two types of reads:
- Eventually Consistent Reads: May not reflect the most recent write operations. The data returned might be stale.
- Strongly Consistent Reads: Guarantee that the most recent data is returned, reflecting all successful write operations.
Why the Other Options are Incorrect
- Option A: Uses an LSI (correct) but with eventually consistent reads (incorrect for the "latest data" requirement).
- Option C: Uses a GSI (incorrect partition key requirement) with eventually consistent reads (also incorrect for consistency).
- Option D: Uses a GSI (incorrect) with strongly consistent reads. Additionally, GSIs only support eventually consistent reads, making this option doubly wrong.
Community Consensus
The community overwhelmingly agrees with Option B (82 votes), with only a small fraction (18 votes) choosing D. Experienced candidates correctly identify that LSIs share the same partition key and that strongly consistent reads are necessary for the latest data.
Official Reference
Exam Strategy
When a DynamoDB question mentions 'same partition key, different sort key,' immediately think LSI. When it mentions 'latest data' or 'all recent writes,' think strongly consistent reads. Eliminate options that mix these concepts incorrectly.
Related Analysis
Practice All DVA-C02 Questions
Access 100 questions with complete answers and detailed explanations.
View Full DVA-C02 Practice Test →