Recipes for Cloud Platforms

AWS

S3

Connect to bucket

import boto3 
from botocore.client import Config

s3 = boto3.resource('s3',
                    endpoint_url='ENDPOINT_URL',
                    aws_access_key_id='AWS_ACCESS_KEY_ID',
                    aws_secret_access_key='AWS_SECRET_ACCESS_KEY',
                    config=Config(signature_version='s3v4'),
                    region_name='us-east-1')

bucket = s3.Bucket('mybucket')

List all buckets

[f for f in s3.buckets.all()]
[s3.Bucket(name='mybucket')]

List contents of bucket

[f for f in bucket.objects.all()]
[s3.ObjectSummary(bucket_name='mybucket', key='reaver.gif'),
 s3.ObjectSummary(bucket_name='mybucket', key='reaver.png')]

Upload to bucket

bucket.upload_file('local_path', 'destination_name')

Download from bucket

bucket.download_file('source_name', 'local_path')

Azure

Minio*

You can use either:

Minio API

Connect to bucket

from minio import Minio

client = Minio(endpoint='ENDPOINT_URL',
               access_key='ACCESS_KEY',
               secret_key='SECRET_KEY')

List all buckets

client.list_buckets()
[<minio.datatypes.Bucket at 0x7f0cc0d09040>]

List contents of bucket

client.list_objects('mybucket')
<generator object Minio._list_objects at 0x7f0cc09eb3c0>

Upload to bucket

client.fput_object(bucket_name='mybucket',
                   object_name='destination_name',
                   file_path='local_path')
<minio.helpers.ObjectWriteResult at 0x7f0cc2a67e20>

Download from bucket

client.fget_object(bucket_name='mybucket',
                   object_name='source_name',
                   file_path='local_path')
<minio.datatypes.Object at 0x7f0cc2a0c4c0>