내용으로 건너뛰기

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개 답변
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

전문가
답변함 10달 전
전문가
검토됨 10달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.