DVA-C03 practice question: DynamoDB keys, indexes and consistency (1 of 2)
Development with AWS Services A free question from our original DVA-C03 practice exam. Try it, then open the answer to see why each option is right or wrong.
A ticket-booking app stores tickets in a DynamoDB table named Tickets, with TicketId as the partition key.
The table has been in production for two years and holds 40 million items. Support staff must find every ticket for a given email address, and the lookup must not scan the table. The change must not rebuild the table.
What should the developer do?
Choose one answer.
AA. Add a local secondary index with EmailAddress as its partition key.
BB. Run a Scan with a FilterExpression on EmailAddress for each support lookup.
CC. Add a global secondary index keyed on EmailAddress, and query it by email.
DD. Change the table's partition key to EmailAddress by calling UpdateTable on the table.
Show the answer and explanation
Answer: C
A. Wrong: A local secondary index must use the table's partition key, which here is TicketId. It also has to be created with the table, so it cannot be added to this table now.
B. Wrong: A scan reads the whole table and filters the results afterwards. It becomes slower and more costly as the table grows, which the team wants to avoid.
D. Wrong: A table's primary key cannot be changed after creation. A new table would have to be created and the data migrated into it.
Explanation
A global secondary index can have its own partition key, which can be any scalar attribute, and it can be added to a table that is already in production. A local secondary index shares the table partition key and must be created with the table. A query on the new index replaces the scan.
Want more on DynamoDB keys, indexes and consistency? The 5 full-length practice sets have 7 more DynamoDB keys, indexes and consistency questions, 390 in all, none of them in the free exam. One payment of $14.99, no subscription. See the practice sets →