How to automate DynamoDB item expiration and archival with minimal code?
Short answer
A Enable TTL on the expirationDate attribute in the table. Create a DynamoDB stream. Create an AWS Lambda function to process the deleted items. Create a DynamoDB trigger for the Lambda function.
Question
Key Takeaways
This question tests the combination of DynamoDB TTL for automatic expiration and DynamoDB Streams to capture the deletion event, eliminating the need for custom scanning and deletion code.
DynamoDB TTL automatically deletes expired items, and when combined with DynamoDB Streams and a Lambda trigger, it provides a code-free expiration mechanism that also captures deleted items for archival processing.
Common mistake: Candidates often choose option C, assuming they must manually scan the table and delete items via Lambda and EventBridge, because they overlook that DynamoDB TTL natively handles expiration without any custom deletion logic.
Expert Analysis
Understanding the Requirement
The application currently uses an expirationDate attribute to find, archive, and delete items from a DynamoDB table. The developer needs a replacement that requires the least amount of code. The key operations are:
1. Automatic deletion of items past their expiration date.
2. Archival/processing of those deleted items.
Why Option A is Correct
Option A leverages three native AWS features working together:
- DynamoDB TTL (Time to Live): You enable TTL on the
expirationDateattribute. DynamoDB automatically identifies and deletes items whose timestamp is older than the current time. This requires zero code for the deletion process. - DynamoDB Streams: When TTL deletes an item, the deletion is recorded in the DynamoDB Stream as a
REMOVEevent. - AWS Lambda Trigger: By creating a DynamoDB trigger on the stream, the Lambda function is automatically invoked with the deleted item data, allowing the developer to archive or process the item.
Why the Other Options are Incorrect
- Option B: Requires writing custom Lambda functions to scan the table, evaluate expiration dates, and call
DeleteItem. This is significantly more code and operational overhead than using TTL. - Option C: Similar to B, it relies on an EventBridge rule to invoke Lambda for scanning and deleting. It also incorrectly suggests using
GetRecordsdirectly on the DynamoDB table (Streams are required forGetRecords). This is the most code-heavy approach. - Option D: DynamoDB TTL does not support sending deleted items directly to an SQS dead-letter queue. TTL deletions can only be captured via DynamoDB Streams. This option describes a non-existent feature.
Community Consensus
The community unanimously agrees on Option A (100% vote). Commenters highlight that TTL + Streams + Lambda is the standard, most efficient pattern for this use case, completely eliminating the need for custom deletion logic.
Community Votes
100% of anonymous learners picked answer A. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 5 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 5
-
SerialiDr 👍 3 Answered AA. Enable TTL (Time to Live) on the expirationDate attribute in the table. Create a DynamoDB stream. Create an AWS Lambda function to process the deleted items. Create a DynamoDB trigger for the Lambda function. This approach leverages DynamoDB's TTL feature to automatically delete items past their expiration date, minimizing the need for custom code to manage this process. The use of a DynamoDB stream and a Lambda function triggered by this stream allows for processing or archiving the items just before they are deleted, without the need to manually scan and delete expired items, thereby significantly reducing operational complexity and code maintenance.
-
CrescentShared 👍 3 Answered ANot sure why C. A can totally handle this.
-
KarBiswa 👍 1 Answered AIt is TTL and stream combination. It will be utilized by the Lambda
-
65703c1 👍 2 Answered AA is the correct answer.
-
Abdullah22 👍 1 Answered Agoing with A
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.
Related Analysis
Practice All DVA-C02 Questions
Access 100 questions with complete answers and detailed explanations.
View Full DVA-C02 Practice Test →