Boto3, s3 folder is not deleted

I have a directory in my s3 bucket 'test', I want to delete this directory. This is what I do

s3 = boto3.resource('s3')
s3.Object(S3Bucket,'test').delete()

and get an answer like this

{'ResponseMetadata': {'HTTPStatusCode': 204, 'HostId': '************', 'RequestId': '**********}}}

but my directory is not deleted!

I tried with all combinations of "/ test", "test /" and "/ test /", etc., also with the file inside this directory and with an empty directory, and all failed to delete the "test".

+4
source share
2 answers

delete_objects HTTP-. 1000 .

https://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Bucket.delete_objects

import boto3

s3 = boto3.resource('s3')
bucket = s3.Bucket('my-bucket')

objects_to_delete = []
for obj in bucket.objects.filter(Prefix='test/'):
    objects_to_delete.append({'Key': obj.key})

bucket.delete_objects(
    Delete={
        'Objects': objects_to_delete
    }
)
+19

. . .


S3 , . /, prefix/my-key.txt, AWS , .

"", , . , boto3 , . , - :

s3 = boto3.resource('s3')
bucket = s3.Bucket('my-bucket-name')
for obj in bucket.objects.filter(Prefix='test/'):
    s3.Object(bucket.name, obj.key).delete()
+11

Source: https://habr.com/ru/post/1611442/


All Articles