DVA-C02 practice question 22 of 35

A developer is creating an AWS Lambda function that searches for Items from an Amazon DynamoDQ table that contains customer contact information. The…

Full set: 598 questions

Domain Troubleshooting and Optimization

A developer is creating an AWS Lambda function that searches for Items from an Amazon DynamoDQ table that contains customer contact information. The DynamoDB table items have the customers as the partition and additional properties such as customer -type, name, and job_title. The Lambda function runs whenever a user types a new character into the customer_type text Input. The developer wants to search to return partial matches of all tne email_address property of a particular customer type. The developer does not want to recreate the DynamoDB table. What should the developer do to meet these requirements?
Answer options
A: Add a global secondary index (GSI) to the DynamoDB table with customer-type input, as the partition key and email_address as the sort key. Perform a query operation on the GSI by using the begins with key condition expression with the email_address property. Correct answer
B: Add a global secondary index (GSI) to the DynamoDB table with email_address as the partition key and customer_type as the sort key. Perform a query operation on the GSI by using the begine_with key condition expresses with the email. Address property.
C: Add a local secondary index (LSI) to the DynemoOB table with customer_type as the partition Key and email_address as the sort Key. Perform a quick operation on the LSI by using the begine_with Key condition expression with the email-address property.
D: Add a local secondary index (LSI) to the DynamoDB table with job-title as the partition key and email_address as the sort key. Perform a query operation on the LSI by using the begins_with key condition expression with the email_address property.
Correct Answer:
A. Add a global secondary index (GSI) to the DynamoDB table with customer-type input, as the partition key and email_address as the sort key. Perform a query operation on the GSI by using the begins with key condition expression with the email_address property.
Explanation

The requirement is to efficiently search for items by a specific customer-type and perform a partial-match search on the emailaddress. A DynamoDB Query operation is the most efficient method for this. A Query requires an equality condition on the partition key and can use a beginswith condition on the sort key. Since the table already exists, a Global Secondary Index (GSI) must be used, as Local Secondary Indexes (LSIs) can only be created when the table is created. By creating a GSI with customer-type as the partition key and emailaddress as the sort key, the Lambda function can issue a Query that efficiently filters by customer-type and then applies the beginswith operator to the emailaddress sort key to find partial matches.

Why Incorrect

B. A Query operation requires an exact match on the partition key. The beginswith condition cannot be used on a partition key, only on a sort key.
C. A Local Secondary Index (LSI) cannot be added to an existing DynamoDB table. It must be defined at the time of table creation, which violates the problem's constraint.
D. A Local Secondary Index (LSI) cannot be added to an existing table. Additionally, using job-title as the partition key does not align with the search requirement, which is based on customer-type.

References

1. AWS DynamoDB Developer Guide - Global Secondary Indexes: "Unlike local secondary indexes, you can create and delete global secondary indexes on an existing table." This supports the choice of a GSI over an LSI for an existing table. (See section: Global secondary indexes)

2. AWS DynamoDB Developer Guide - Working with Queries in DynamoDB: "The KeyConditionExpression parameter specifies the search criteria. You must specify the partition key name and value as an equality condition. You can optionally provide a second condition for the sort key." This confirms the structure of a Query. (See section: Query)

3. AWS DynamoDB Developer Guide - Condition Expressions: "The beginswith function is a supported key condition expression for the sort key attribute." This confirms that beginswith can be used on the sort key as proposed in the correct answer. (See section: Comparison Operator and Function Reference)

4. AWS DynamoDB Developer Guide - Local Secondary Indexes: "You can define a maximum of five local secondary indexes when you create a table." This confirms that LSIs must be created with the table and cannot be added later. (See section: Local secondary indexes)

Scroll to Top