Question #645
A company stores user activity logs for a web application in an Amazon DynamoDB table. The company wants an automated method to remove outdated entries from the table.
What is the most straightforward way to achieve this?
Develop a script to delete outdated records; schedule the script using AWS Lambda triggered by Amazon EventBridge.
Add an attribute containing the expiration timestamp; enable the Time To Live (TTL) feature using that attribute.
Weekly, generate a new table for activity logs; delete the prior week's table.
Include an attribute named 'expiryDate' to track deletion times without enabling TTL.
Explanation
Answer B is correct because DynamoDB's Time to Live (TTL) feature allows automatic deletion of outdated items when a predefined expiration timestamp attribute is set. This requires minimal configuration and avoids the need for custom scripts or manual processes.
Why other options are incorrect:
- A: While feasible, this approach requires writing, scheduling, and maintaining a script, making it less straightforward than TTL.
- C: Creating and deleting tables weekly is inefficient, complicates data management, and risks accidental data loss.
- D: Adding an 'expiryDate' without enabling TTL does nothing; a separate process would still be needed to delete items.
Key Points:
- TTL is a built-in DynamoDB feature for automatic item expiration.
- TTL requires an attribute storing the expiration timestamp (epoch time).
- AWS handles the deletion process, reducing operational overhead.
Answer
The correct answer is: B