Skip to Content

Amazon DVA-C02: Efficiently Query Amazon DynamoDB Table with Global Secondary Index

Learn the most efficient way to retrieve specific records from a large Amazon DynamoDB table using a global secondary index and a Query operation.

Table of Contents

Question

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?

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.

Answer

The most efficient solution to retrieve all Orders records that contain an OrderSource attribute with the MobileApp value is Option D: Create a global secondary index (GSI) with OrderSource as the partition key. Perform a Query operation by using MobileApp as the key.

Explanation

Creating a global secondary index with OrderSource as the partition key will allow efficient querying of the Orders table by OrderSource. Unlike a local secondary index, a global secondary index has its own partition key which can be different from the base table’s partition key. This allows querying the table using an alternate key.

Once the GSI is created with OrderSource as the partition key, a Query operation can be performed using MobileApp as the partition key value. This will efficiently retrieve only the records where OrderSource equals MobileApp.

A Scan operation (Option A) is inefficient as it reads every item in the table and then filters out the matching items. This consumes a lot of read capacity for a large table.

Creating an LSI (Option B) requires the same partition key as the base table. Since the base table uses OrderID as the partition key, an LSI cannot be created with OrderSource as the partition key.

Option C suggests creating a GSI with OrderSource as the sort key. However, the sort key is used in conjunction with the partition key for sorting and range queries. To query the GSI directly by OrderSource, it needs to be the partition key, not the sort key.

Therefore, Option D provides the most efficient solution by creating a GSI with OrderSource as the partition key, enabling fast querying of MobileApp orders.

Amazon AWS Certified Developer – Associate DVA-C02 certification exam practice question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the Amazon AWS Certified Developer – Associate DVA-C02 exam and earn Amazon AWS Certified Developer – Associate DVA-C02 certification.