What is the MOST cost-effective way to delete posts that are older than 48 hours?
For each item, add a new attribute of type String that has a timestamp that is set to the blog post creation time. Create a script to find old posts with a table scan and remove posts that are older than 48 hours by using the BatchWriteItem API operation. Schedule a cron job on an Amazon EC2 instance once an hour to start the script.
For each item, add a new attribute of type String that has a timestamp that is set to the blog post creation time. Create a script to find old posts with a table scan and remove posts that are older than 48 hours by using the BatchWriteItem API operation. Place the script in a container image. Schedule an Amazon Elastic Container Service (Amazon ECS) task on AWS Fargate that invokes the container every 5 minutes.
For each item, add a new attribute of type Date that has a timestamp that is set to 48 hours after the blog post creation time. Create a global secondary index (GSI) that uses the new attribute as a sort key. Create an AWS Lambda function that references the GSI and removes expired items by using the BatchWriteItem API operation. Schedule the function with an Amazon CloudWatch event every minute.
For each item, add a new attribute of type Number that has a timestamp that is set to 48 hours after the blog post creation time. Configure the DynamoDB table with a TTL that references the new attribute.
Explanations:
This option involves scanning the entire table to find old posts, which can be costly and inefficient given the scale (millions of posts daily). Running a cron job on an EC2 instance adds operational overhead and does not utilize DynamoDB’s TTL features, leading to unnecessary complexity and cost.
Similar to option A, this approach also requires scanning the table, which is inefficient. While using ECS on Fargate reduces operational overhead compared to EC2, it still does not leverage DynamoDB’s built-in TTL feature, leading to higher costs and complexity without a significant performance gain.
This option suggests creating a GSI and scheduling a Lambda function to delete expired posts. However, it still requires regular scanning of items and could be more costly than necessary since it does not leverage TTL for automated deletions, making it less efficient.
This is the most cost-effective option as it utilizes DynamoDB’s Time to Live (TTL) feature. By setting a TTL attribute that automatically deletes items after 48 hours, it eliminates the need for regular scans or manual deletions, significantly reducing operational overhead and cost while ensuring that expired items are cleaned up efficiently.