AWS Certified Developer – Associate (DVA-C02) — Question 363
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?
Answer options
- A. Add a local secondary index (LSI) during table creation. Query the LSI by using eventually consistent reads.
- B. Add a local secondary index (LSI) during table creation. Query the LSI by using strongly consistent reads.
- C. Add a global secondary index (GSI) during table creation. Query the GSI by using eventually consistent reads.
- D. Add a global secondary index (GSI) during table creation. Query the GSI by using strongly consistent reads.
Correct answer: B
Explanation
To query an Amazon DynamoDB table using the same partition key but an alternative sort key, a local secondary index (LSI) must be defined during table creation. Furthermore, because the application requires the most up-to-date data, strongly consistent reads are required, which are supported by LSIs but not by global secondary indexes (GSIs). Therefore, creating an LSI and querying it with strongly consistent reads is the correct approach.