AWS Certified Developer – Associate (DVA-C02) — Question 365
A developer is working on an app for a company that uses an Amazon DynamoDB table named Orders to store customer orders. The table uses OrderID as the partition key and there is no sort key. The table contains more than 100,000 records. The developer needs to add a functionality that will retrieve all Orders records that contain an OrderSource attribute with the MobileApp value.
Which solution will improve the user experience in the MOST efficient way?
Answer options
- A. Perform a Scan operation on the Orders table. Provide a QueryFilter condition to filter to only the items where the OrderSource attribute is equal to the MobileApp value.
- B. Create a local secondary index (LSI) with OrderSource as the partition key. Perform a Query operation by using MobileApp as the key.
- C. Create a global secondary index (GSI) with OrderSource as the sort key. Perform a Query operation by using MobileApp as the key.
- D. Create a global secondary index (GSI) with OrderSource as the partition key. Perform a Query operation by using MobileApp as the key.
Correct answer: D
Explanation
Creating a Global Secondary Index (GSI) with OrderSource as the partition key allows the developer to use the highly efficient Query operation to find all matching items instantly. Performing a Scan operation is highly inefficient and slow for tables with more than 100,000 records because it reads every item in the table. An LSI cannot be used here because it requires the same partition key as the base table, and configuring OrderSource as a GSI sort key without a GSI partition key does not allow querying by OrderSource directly.