Skip to content

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 Answer
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

EXPERT
answered 9 months ago
EXPERT
reviewed 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.