Skip to main content

AWS DVA-C02 Drill: DynamoDB Querying - Minimizing Read Capacity Usage

Jeff Taakey
Author
Jeff Taakey
21+ Year Enterprise Architect | AWS SAA/SAP & Multi-Cloud Expert.

Jeff’s Note
#

Unlike generic exam dumps, ADH analyzes this scenario through the lens of a Real-World Lead Developer.

For DVA-C02 candidates, the confusion often lies in choosing the optimal DynamoDB API call to minimize read capacity unit consumption. In production, this is about knowing exactly when to use Query vs Scan and how global secondary indexes impact efficiency. Let’s drill down.

The Certification Drill (Simulated Question)
#

Scenario
#

A fintech startup called “FinSolve” maintains a DynamoDB table named transactions to track user purchases. The table uses a primary partition key named transactionId and has a global secondary index (GSI) called userIndex, which has userId as a partition key and transactionTimestamp as a sort key. The development team needs to create an AWS Lambda function to efficiently retrieve all transactions for a particular userId (value: 100) using the least amount of read capacity.

The Requirement:
#

Implement a DynamoDB data retrieval method in Lambda that fetches all items with userId = 100, using minimal read capacity.

The Options
#

  • A) Use the GetItem API operation with parameters: "TableName": "transactions", "Key": { "userId": {"S": "100"} }
  • B) Use the BatchGetItem API operation with parameters: "RequestItems": { "transactions": { "Keys": [{ "userId": {"S": "100"} }] } }
  • C) Use the Scan API operation with parameters: { "TableName": "transactions", "FilterExpression": "userId = :userId", "IndexName": "userIndex", "ExpressionAttributeValues": { ":userId": {"S": "100"} } }
  • D) Use the Query API operation with parameters: "TableName": "transactions", "IndexName": "userIndex", "KeyConditionExpression": "userId = :userId", "ExpressionAttributeValues": { ":userId": {"S": "100"} }

Google adsense
#

leave a comment:

Correct Answer
#

D

Quick Insight: The Developer Imperative
#

DynamoDB Query operations on a GSI are designed to efficiently retrieve all items matching a partition key condition with optimized read capacity consumption, unlike Scan which reads the entire index and filters afterward. GetItem and BatchGetItem require full primary key values, which are not suitable here since the query is on the GSI.

Content Locked: The Expert Analysis
#

You’ve identified the answer. But do you know the implementation details that separate a Junior from a Senior?


The Expert’s Analysis
#

Correct Answer
#

Option D

The Winning Logic
#

A DynamoDB Query operation on the userIndex GSI specifically retrieves all items with a partition key of userId = 100 in a highly efficient manner. This avoids scanning the entire table or index and thus consumes the least read capacity units (RCUs). Query uses the KeyConditionExpression to directly fetch matching partitions, which is optimal for this use case.

The Trap (Distractor Analysis):
#

  • Why not A? GetItem requires a full primary key (partition and sort key if any). Here, userId is only a GSI partition key, so it cannot be used alone with GetItem. This request would fail or return unexpected results.
  • Why not B? BatchGetItem works with full primary keys and is designed for fetching multiple specific items by their exact keys. It cannot fetch items by GSI partition key alone.
  • Why not C? Scan with a filter reads every item (or every index entry if specifying IndexName) and then filters client-side. This has the highest read capacity cost and latency among the options and should be avoided if possible.

The Technical Blueprint
#

// Example Lambda function snippet to perform the Query operation
const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB();

const params = {
  TableName: 'transactions',
  IndexName: 'userIndex',
  KeyConditionExpression: 'userId = :userId',
  ExpressionAttributeValues: {
    ':userId': { S: '100' }
  }
};

exports.handler = async () => {
  try {
    const result = await dynamodb.query(params).promise();
    return result.Items;
  } catch (error) {
    console.error('Error querying DynamoDB:', error);
    throw error;
  }
};

The Comparative Analysis
#

Option API Complexity Performance Use Case
A Simple but incorrect usage Invalid request (wrong key) Requires full PK; can’t query by GSI key
B Moderate Inefficient & inappropriate Batch gets require full primary keys
C Simple Highest latency and RCU cost Scans entire index; least efficient
D Moderate Most efficient; lowest RCU cost Correct usage of Query on GSI to fetch by partition key

Real-World Application (Practitioner Insight)
#

Exam Rule
#

“For the exam, always pick Query when you need to fetch all items by a known partition key, especially using a GSI.”

Real World
#

“In real production systems, leveraging Query over Scan drastically reduces costs and improves latency, and is a foundational pattern for efficient DynamoDB data access.”


(CTA) Stop Guessing, Start Mastering
#


Disclaimer

This is a study note based on simulated scenarios for the AWS DVA-C02 exam.

The DevPro Network: Mission and Founder

A 21-Year Tech Leadership Journey

Jeff Taakey has driven complex systems for over two decades, serving in pivotal roles as an Architect, Technical Director, and startup Co-founder/CTO.

He holds both an MBA degree and a Computer Science Master's degree from an English-speaking university in Hong Kong. His expertise is further backed by multiple international certifications including TOGAF, PMP, ITIL, and AWS SAA.

His experience spans diverse sectors and includes leading large, multidisciplinary teams (up to 86 people). He has also served as a Development Team Lead while cooperating with global teams spanning North America, Europe, and Asia-Pacific. He has spearheaded the design of an industry cloud platform. This work was often conducted within global Fortune 500 environments like IBM, Citi and Panasonic.

Following a recent Master’s degree from an English-speaking university in Hong Kong, he launched this platform to share advanced, practical technical knowledge with the global developer community.


About This Site: AWS.CertDevPro.com


AWS.CertDevPro.com focuses exclusively on mastering the Amazon Web Services ecosystem. We transform raw practice questions into strategic Decision Matrices. Led by Jeff Taakey (MBA & 21-year veteran of IBM/Citi), we provide the exclusive SAA and SAP Master Packs designed to move your cloud expertise from certification-ready to project-ready.