user2175783
user2175783

Reputation: 1431

Automatically delete certain s3 objects with a given extension and older than a certain date

Is there a way similar to an S3 lifecycle policy (or just an s3 bucket policy) that will automatically delete objects in a bucket older than x days and with a given file extension? Depending on the extension it might be a bucket wide delete action or only delete objects under certain prefixes.

Upvotes: 1

Views: 2077

Answers (2)

Giovanni Pedretti
Giovanni Pedretti

Reputation: 71

If you are uploading your files using S3 (PutObject, etc...), you can tag your objects and then use the tag to delete them using the S3 lifecycles.

Upvotes: 0

Marcin
Marcin

Reputation: 238071

with a given file extension

Sadly you can't do this with S3 lifecycles, as they only work based on prefix, not suffix such as an extension.

This means you need a custom solution for that problem. Depending on exact nature of the issue (number of files, how frequently do you want to perform the deletion operation), there are several ways for doing this. They including running a single lambda on schedule, S3 Batch operations, using DynamoDB to store the metadata, and so on.

Upvotes: 3

Related Questions