AWS Certified Developer – Associate / Question #628 of 557

Question #628

A developer is working on an existing application that uses Amazon DynamoDB as its data store. The DynamoDB table has the following attributes: userID (partition key), timestamp (sort key), category, subcategory, and status. When the developer analyzes the usage patterns, the developer notices that there are application modules that frequently look for a list of items based on the category and subcategory attributes.

The developer wants to make changes to the application to improve performance of the query operations.

Which solution will meet these requirements?

A

Create a global secondary index (GSI) with category as the partition key and subcategory as the sort key.

B

Create a local secondary index (LSI) with category as the partition key and subcategory as the sort key.

C

Recreate the table. Add userID as the partition key and timestamp as the sort key. During table creation, add a local secondary index (LSI) with category as the partition key and subcategory as the sort key.

D

Update the queries to use Scan operations with category as the partition key and subcategory as the sort key.

Explanation

The correct answer is A. A GSI enables querying on attributes not part of the base table's primary key. Since the existing table uses userID (partition key) and timestamp (sort key), queries on category and subcategory require a new index. A GSI with category as the partition key and subcategory as the sort key optimizes these queries.

Option B is incorrect because LSIs must share the base table's partition key (userID), which does not align with the query pattern. Option C is invalid because recreating the table and adding an LSI is unnecessary and LSIs cannot be added after table creation. Option D is inefficient because Scan operations are slow and resource-intensive. GSIs are the best solution for this scenario, as they can be added to an existing table and support flexible query patterns.

Answer

The correct answer is: A