AWS Certified Developer – Associate / Question #687 of 557

Question #687

A developer is working on a web application that uses Amazon DynamoDB as its data store. The application has two DynamoDB tables: one table named customers and one table named orders. The customers table uses customerID as the partition key. The orders table uses orderID as the partition key and customerID as the sort key.

The application requires retrieving multiple orders and their associated customer details in a single database operation to minimize network traffic and ensure optimal performance.

Which solution meets these requirements?

A

Perform a BatchGetItem operation that returns items from both tables. Use the list of orderID/customerID keys for the orders table and the list of customerID keys for the customers table.

B

Perform a Scan operation on each table, filtering by the list of orderID/customerID keys for the orders table and the list of customerID keys for the customers table.

C

Perform a BatchGetItem operation on the orders table using orderID/customerID keys. Perform a separate BatchGetItem operation on the customers table using customerID keys.

D

Create a global secondary index (GSI) on the orders table with customerID as the partition key. Perform a Query operation for each customerID on the orders table and a separate Query operation for each customerID on the customers table.

Explanation

Option A is correct because DynamoDB's BatchGetItem operation can fetch items from multiple tables in one request. By specifying the orderID/customerID keys for the orders table and customerID keys for the customers table, the application retrieves all required data efficiently. This reduces network round-trips compared to separate operations (Option C) and avoids inefficient Scans (Option B) or multiple Query operations with a GSI (Option D). BatchGetItem is designed for bulk retrieval of items across tables, aligning with the requirement for minimal network traffic and optimal performance.

Key Points:
- BatchGetItem supports multi-table retrieval in a single request.
- Scans are inefficient and not suitable for targeted lookups.
- Separate BatchGetItem operations (Option C) increase network traffic.
- GSIs (Option D) add complexity and require multiple queries.

Answer

The correct answer is: A