AWS Certified Developer – Associate (DVA-C02) — Question 373
A developer is creating a web application for a school that stores data in Amazon DynamoDB. The ExamScores table has the following attributes: student_id, subject_name, and top_score.
Each item in the ExamScores table is identified with student_id as the partition key and subject_name as the sort key. The web application needs to display the student _id for the top scores for each school subject. The developer needs to increase the speed of the queries to retrieve the student_id for the top scorer for each school subject.
Which solution will meet these requirements?
Answer options
- A. Create a local secondary index (LSI) with subject_name as the partition key and top_score as the sort key.
- B. Create a local secondary index (LSI) with top_score as the partition key and student_id as the sort key.
- C. Create a global secondary index (GSI) with subject_name as the partition key and top_score as the sort key.
- D. Create a global secondary index (GSI) with subject_name as the partition key and student_id as the sort key.
Correct answer: C
Explanation
To query data across the entire table using an attribute other than the base table's partition key, a global secondary index (GSI) is required, because a local secondary index (LSI) is restricted to using the same partition key as the main table. Creating a GSI with subject_name as the partition key and top_score as the sort key allows the application to efficiently query and sort the scores to find the top student_id for each subject. Option D is incorrect because it does not include top_score as the sort key, which is necessary to easily retrieve the highest score.