Как они уже предложили, boto3 прост в использовании.
Здесь приведены мои функции для установки и получения объекта в / из корзины s3.
def putdataons3(localfile, remotefile):
try:
bucket = 'yourbucket'
boto3accesskey = 'your access key'
boto3secretaccesskey = 'your secret access key'
boto3client = boto3.client('s3', region_name='eu-central-1', aws_access_key_id=boto3accesskey, aws_secret_access_key=boto3secretaccesskey)
d = boto3client.put_object(Body=open(localfile, 'rb').read(), Bucket=bucket, Key=remotefile)
if d['ResponseMetadata']['HTTPStatusCode'] == 200:
return True
return False
except:
return False
def getdatafroms3(remotefile, localfile, overwrite=True):
try:
if overwrite == False:
if os.path.isfile(localfile):
return False
bucket = 'yourbucket'
boto3accesskey = 'your access key'
boto3secretaccesskey = 'your secret access key'
boto3client = boto3.client('s3', region_name='eu-central-1', aws_access_key_id=boto3accesskey, aws_secret_access_key=boto3secretaccesskey)
d = boto3client.get_object(Bucket=bucket, Key=remotefile)
if d['ResponseMetadata']['HTTPStatusCode'] == 200:
f = open(localfile, "wb")
d = d['Body'].read()
f.write(d)
f.close()
return True
return False
except:
return False