Boto3 delete objects with BucketObjectsCollection

0

I am using the boto3 S3 resource to access objects in S3 and later delete all the files. However, the deletion operation could end up leaving one file un-deleted from time to time.

Here is what my code looks like:

s3 = boto3.resource("s3")

# Iterate through a list of prefixes
for some_prefix in list_of_prefixes:
    bucket = s3.Bucket("some_bucket_name")

    # For each prefix, get all the objects with the prefix, do some processing, and finally delete all the processed objects
    bucket_objects = bucket.objects.filter(some_prefix)
    ... <do something with the objects>
    bucket_objects.delete()

To troubleshoot, I added logging in the <do something with the objects> section and made sure that the un-deleted file was part of the bucket_objects BucketObjectsCollection.

Here are more details:

  • There are about ~200 files under each prefix
  • There were no exceptions or errors raised by the S3 resource

Thank you so much for your help!

질문됨 일 년 전80회 조회
답변 없음

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

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

질문 답변하기에 대한 가이드라인

관련 콘텐츠