Jamie Howard
Jamie Howard

Reputation: 11

How to delete x old files in amazon s3 using amazon CLI

I have found this regarding deletion of old files in bash: Delete all but the most recent X files in bash

I want the same functionality, however I cannot apply the same principles in my script as it is interacting with an amazon s3 directory.

Does anyone know how to use amazon CLI to achieve this?

Upvotes: 0

Views: 614

Answers (1)

Luc Hendriks
Luc Hendriks

Reputation: 2533

Well you can just create a lifecycle rule on S3 to delete older files. Then this process is done automatically for you.

Otherwise I guess you need to LIST all objects' metadata and write a script that checks if the script is old enough. But if you have a lot of objects this can be quite costly, while the lifecycle rule is free.

Upvotes: 1

Related Questions