I was looking through the boto3 documentation and could not find if it natively supports a check to see if the file already exists in s3 and if not do not try and re-upload.
Here's what I have working:
import boto3
s3_client = boto3.client('s3')
s3_bucket = 'bucketName'
s3_folder = 'folder1234/'
temp_log_dir = "tempLogs/"
s3_client.upload_file(temp_log_dir + file_name, s3_bucket, s3_folder + file_name)
What I'm noticing is that if the file exits in S3 already , the .upload_file() from boto3 still transfers the file. I did this check by looking at iftop.
Is there some arg i'm missing to disable "auto overwrite if file exists"?
Thanks
edit trying the head method
s3 = boto3.resource('s3')
file_name = 'somelogfile.gz'
try:
s3.Object(s3_bucket+ s3_folder+s3_filename).load()
print 'success'
except botocore.exceptions.ClientError as e:
print e