https://boto3.readthedocs.io/en/latest/reference/services/s3.htm
#### pip install boto3==1.6.12
# -*- coding: utf-8 -*-
"""
@contact: lishulong.never@gmail.com
@time: 2018/3/21 上午11:24
"""
from boto3.session import Session
from utils import is_blank
from config import config
aws_access_key_id = config.get('s3_credentials', 'aws_access_key_id')
aws_secret_access_key = config.get('s3_credentials','aws_secret_access_key')
bucket = config.get('s3_credentials', 'bucket')
region = config.get('s3_credentials', 'region')
session = Session(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, region_name=region)
client = session.client('s3')
def down_url_by_key(key: str):
"""
s3 key2url
:param key:
:return:
"""
if is_blank(key):
return None
return client.generate_presigned_url(ClientMethod='get_object', Params=dict(Bucket=bucket, Key=key), ExpiresIn=3600)