DVA-C02 exam dumps

DVA-C02 practice question 100 of 399

AWS Certified Developer - Associate. Associate level, Amazon Web Services. Free question with the correct answer and a full explanation.

DVA-C02 Question 100

Single answer

A developer is designing an application that stores customer orders in an Amazon DynamoDB table. The table's primary key consists of a partition key named 'CustomerID' and a sort key named 'OrderID'. The developer needs to query all orders placed by a specific customer within a given date range. What is the best way to achieve this, considering performance and cost optimization?

  1. A

    Use the Query operation with the 'CustomerID' as the partition key and 'OrderID' as the sort key condition to filter the date range.

  2. B

    Use the Scan operation with a filter expression to retrieve all items and filter the results by 'CustomerID' and 'OrderID' for the date range.

  3. C

    Add a Global Secondary Index (GSI) with 'OrderDate' as the partition key and query the GSI with the date range.

  4. D

    Add a Local Secondary Index (LSI) with 'OrderDate' as the sort key and use the Query operation with 'CustomerID' as the partition key and a sort key condition on 'OrderDate' for the date range.

Show answer and explanation

Correct answer: D

Explanation

To query a specific customer's orders within a date range, a Local Secondary Index (LSI) is the best solution. An LSI allows the same partition key ('CustomerID') but adds a different sort key (e.g., 'OrderDate') for more flexible querying. This approach optimizes both performance and cost by avoiding full table scans and leveraging the Query operation's efficiency. The Scan operation or creating a new GSI would introduce unnecessary complexity and inefficiency.

  • A. Incorrect.

    This option is incorrect because while the Query operation is efficient for finding items within a partition, it cannot natively filter items by a date range unless the sort key ('OrderID') is designed to include date information.

  • B. Incorrect.

    This option is incorrect because the Scan operation is not cost-effective or performant for querying specific items. It scans the entire table and applies filters afterward, which is resource-intensive.

  • C. Incorrect.

    This option is incorrect because a Global Secondary Index (GSI) changes the partition key, which is unnecessary in this scenario. The existing partition key 'CustomerID' is already sufficient to group related data.

  • D. Correct.

    This option is correct because Local Secondary Indexes (LSIs) allow you to define an additional sort key (in this case, 'OrderDate') while retaining the same partition key ('CustomerID'). This enables efficient querying of orders within a date range for a specific customer.

Timed practice exam

Take a DVA-C02 practice test under exam conditions

65 questions in 130 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam