AWS Certified Developer – Associate — Question 380
A developer is designing an Amazon DynamoDB table for an application. The application will store user information that includes a unique identifier and an email address for each user. The application must be able to query the table by using either the unique identifier or the email address.
How should the developer design the DynamoDB table to meet these requirements?
Answer options
- A. For the primary key of the table, specify the unique identifier as the partition key and specify the email address as the sort key.
- B. For the primary key of the table, specify the unique identifier as the partition key. Create a local secondary index (LSI) based on the email address.
- C. For the primary key of the table, specify the email address as the partition key and specify the unique identifier as the sort key.
- D. For the primary key of the table, specify the unique identifier as the partition key. Create a global secondary index (GSI) based on the email address.
Correct answer: D
Explanation
To query a table using two different attributes independently, one attribute must be set as the primary partition key, and a Global Secondary Index (GSI) must be created using the other attribute as its partition key. A Local Secondary Index (LSI) is incorrect because it requires the same partition key as the base table. Using a composite primary key with a sort key (Options A and C) would still require providing the partition key in order to query the table, which does not satisfy the requirement of querying by either attribute alone.