Boto3 S3

From wikinotes

Documentation

client docs https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html?highlight=s3#id201


Connection

session = boto3.session.Session()
client = session.client(
    service_name='S3',
    region='nyc',   # do spaces region code
    endpoint_url='https://nyc.digitaloceanspaces.com',
    aws_access_key_id='JLjk12H/j98afrz+LKJ28jlkJfjxlki12Vahlj12fZM',
    aws_secret_access_key='ALSKDJw3erukljasdf',
)

Search

client.list_objects_v2(Bucket='tma', Prefix='/updates/blah/')

Upload/Download

client.upload_fileobj(fd, Bucket='tma', Key='/updates/mykey')

# download into memory
fd = six.BytesIO()
client.download_fileobj(Bucket=bucket, Key=key, Fileobj=fd)
contents = fd.getvalue()