Q24 — AWS DVA-C02 Ch.3
Question 24 of 100 | ← Chapter 3
A mobile application stores blog posts in an Amazon DynamoDB table. Several new posts are added daily, each represented as a separate item. The application only requires recent posts. Any post older than 48 hours can be deleted. What is the most cost-effective way to delete posts older than 48 hours?
- A. For each item, add a new String-type attribute containing a timestamp set to the blog post creation time. Create a script that uses the BatchWriteItem API operation to find and delete old posts. Schedule the script as a cron job on an Amazon EC2 instance, running hourly.
- B. For each item, add a new String-type attribute containing a timestamp set to the blog post creation time. Create a script that uses the BatchWriteItem API operation to find and delete old posts. Package the script in a container image and schedule an Amazon ECS task on AWS Fargate to run the container every 5 minutes.
- C. For each item, add a new Date-type attribute containing a timestamp set to 48 hours after the blog post creation time. Create a Global Secondary Index (GSI) using the new attribute as the sort key. Create an AWS Lambda function that queries the GSI and deletes expired items using BatchWriteItem. Schedule the function using Amazon CloudWatch Events every minute.
- D. For each item, add a new Number-type attribute containing a timestamp set to 48 hours after the blog post creation time. Configure the DynamoDB table to use TTL (Time to Live) referencing the new attribute. ✓
Correct Answer: D. For each item, add a new Number-type attribute containing a timestamp set to 48 hours after the blog post creation time. Configure the DynamoDB table to use TTL (Time to Live) referencing the new attribute.
Explanation
DynamoDB’s built-in Time-to-Live (TTL) feature is the most cost-effective and operationally efficient solution. By adding a Number-type attribute (epoch timestamp) representing the expiration time (creation time + 48 hours) and enabling TTL on that attribute, DynamoDB automatically deletes expired items without requiring custom code, infrastructure, or polling. Options A, B, and C all involve custom logic, compute resources (EC2, Fargate, Lambda), scheduling, and ongoing maintenance — increasing cost and complexity. TTL incurs no additional charge and scales automatically. Therefore, option D is optimal.