A DynamoDB table stores session records that should be automatically removed roughly a day after they expire, without the application running a scheduled job to scan and delete old items, and without consuming any write capacity for the expiring items. Which feature should the team configure, and what must the expiration attribute contain?
- DynamoDB Streams, configured to trigger a Lambda function that deletes each item once its session attribute indicates expiry
- A global secondary index on a session-expiry attribute, combined with a scheduled Scan that deletes items older than the cutoff
- On-demand backups scheduled daily, restoring only the non-expired items into a new table each day
- Time to Live (TTL), pointed at an attribute holding the expiration time as a Number in Unix epoch seconds; DynamoDB deletes expired items automatically, typically within a few days, without consuming write throughput
Why D? And why not the others?
Correct answer: D. Time to Live (TTL), pointed at an attribute holding the expiration time as a Number in Unix epoch seconds; DynamoDB deletes expired items automatically, typically within a few days, without consuming write throughput
Time to Live works by reading a designated attribute that must be a Number storing the expiration time in Unix epoch seconds, and once that time has passed, DynamoDB's own background process deletes the item automatically, typically within a few days, without consuming any write capacity for the deletion, exactly matching the stated requirements. The option describing Streams triggering a Lambda deletion is wrong because that approach requires custom code to inspect items and issue deletes, and each of those application-driven deletes does consume write capacity, unlike TTL's built-in background process. The option describing a GSI with a scheduled Scan is wrong because it still requires the application to run and pay for a recurring scan-and-delete job, which is exactly the scheduled maintenance work the team wants to avoid. The option describing daily on-demand backups is wrong because backups create full point-in-time snapshots for recovery purposes; restoring non-expired items into a new table each day does not delete anything from the live table and is not an expiration mechanism at all.
Source: AWS DynamoDB documentation: Using Time to Live (TTL) in DynamoDB