Direkt zum Inhalt

Delete object only with standard storage class in S3

0

I have an S3 bucket containing 7 TB of data, with approximately 6 TB stored in the Standard storage class (around 40 million objects) and the rest in Glacier. I need to delete all objects in the Standard storage class while retaining those in Glacier. Since the objects are randomly distributed within the bucket, there is no specific folder to target for Standard storage class objects, making lifecycle rules unsuitable for this task.

can somebody suggest an efficient and straightforward approach to achieve this?

Thanks!

1 Antwort
0

A simple shell script should work

List objects with storage class

aws s3api list-objects --bucket YOUR_BUCKET_NAME --query "Contents[?StorageClass=='STANDARD'].[Key]" --output text

Delete only standard class objects

aws s3api list-objects --bucket YOUR_BUCKET_NAME --query "Contents[?StorageClass=='STANDARD'].[Key]" --output text | xargs -I {} aws s3 rm s3://YOUR_BUCKET_NAME/{}

Please test before performing in your Bucket

EXPERTE
beantwortet vor 10 Monaten
EXPERTE
überprüft vor 10 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.