I have the following snippet:
import boto3
session = boto3.Session(
aws_access_key_id="id",
aws_secret_access_key="secret",
region_name="us-east-1"
)
s3 = session.resource("s3")
obj = s3.Object("mybucket", "test.txt")
obj.delete()
It works fine if the file is on the root of the bucket, but I need to delete a file inside a directory. My file is under: mybucket/media/private/test.txt
Adding the path to "mybucket"
or "test.txt"
in the s3.Object()
is not working
The keyname in S3 contains also the directory path, there are no real directories in buckets.
Do it like this:
s3 = session.resource("s3")
obj = s3.Object("mybucket", "media/private/test.txt")
obj.delete()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With