DVA-C02 · Question #103
A company caches session information for a web application in an Amazon DynamoDB table. The company wants an automated way to delete old items from the table. What is the simplest way to do this?
The correct answer is B. Add an attribute with the expiration time; enable the Time To Live feature based on that attribute.. DynamoDB's Time To Live (TTL) feature automatically deletes items once a specified epoch timestamp attribute value is reached, requiring no additional infrastructure or custom code.
Question
A company caches session information for a web application in an Amazon DynamoDB table. The company wants an automated way to delete old items from the table. What is the simplest way to do this?
Options
- AWrite a script that deletes old records; schedule the script as a cron job on an Amazon EC2
- BAdd an attribute with the expiration time; enable the Time To Live feature based on that attribute.
- CEach day, create a new table to hold session data; delete the previous day's table.
- DAdd an attribute with the expiration time; name the attribute ItemExpiration.
How the community answered
(32 responses)- A3% (1)
- B88% (28)
- C6% (2)
- D3% (1)
Why each option
DynamoDB's Time To Live (TTL) feature automatically deletes items once a specified epoch timestamp attribute value is reached, requiring no additional infrastructure or custom code.
Running a deletion script on EC2 as a cron job introduces unnecessary infrastructure overhead and operational complexity compared to the built-in TTL feature.
By adding a Number attribute containing a Unix epoch expiration timestamp and enabling TTL on that attribute name in the DynamoDB table settings, DynamoDB will automatically and asynchronously delete expired items within 48 hours at no additional cost, making it the simplest and most native solution.
Creating and deleting tables daily is operationally complex, risks data loss at table boundaries, and does not provide fine-grained per-item expiration.
Naming an attribute ItemExpiration alone has no effect; TTL must be explicitly enabled in the DynamoDB table configuration and pointed at the specific attribute name.
Concept tested: DynamoDB Time To Live (TTL) for automatic item expiration
Source: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html
Community Discussion
No community discussion yet for this question.