![]() |
Delete files from amazon s3 bucket - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Delete files from amazon s3 bucket (/thread-36070.html) |
Delete files from amazon s3 bucket - python_student - Jan-14-2022 I am trying to delete all files from amazon s3 bucket before executing other tasks that will ingest data. Basically delete files before uploading new files. This is my code to delete files. It`s running successfully, but is not deleting any files. import os import boto3 def clear_bucket(**kwargs): aws = AwsHook(aws_conn_id=kwargs['aws_conn']).get_credentials() os.environ['aws_access_key_id'] = aws[0] os.environ['aws_secret_access_key'] = aws[1] bucket=get_vars['aws_bucket'] prefix=get_vars['aws_folder'] s3 = boto3.client('s3') s3.delete_object(Bucket=bucket, Key=prefix )I also tried with the code below in which it ran successfully but without deleting any files import boto3 s3 = boto3.resource('s3') s3.Object('my-bucket', 'my folder').delete()Any idea why is not deleting files from s3? |