how to delete files from amazon s3 bucket? how to delete files from amazon s3 bucket? python python

how to delete files from amazon s3 bucket?


Using boto3 (currently version 1.4.4) use S3.Object.delete().

import boto3s3 = boto3.resource('s3')s3.Object('your-bucket', 'your-key').delete()


Using the Python boto3 SDK (and assuming credentials are setup for AWS), the following will delete a specified object in a bucket:

import boto3client = boto3.client('s3')client.delete_object(Bucket='mybucketname', Key='myfile.whatever')


found one more way to do it using the boto:

from boto.s3.connection import S3Connection, Bucket, Keyconn = S3Connection(AWS_ACCESS_KEY, AWS_SECERET_KEY)b = Bucket(conn, S3_BUCKET_NAME)k = Key(b)k.key = 'images/my-images/'+filenameb.delete_key(k)