Skip to content

Python Boto3

Python Boto3 is a programming API for accessing S3 buckets.

Access credentials

Copy access keys from ICE Connect

Services ➡ S3 Storage ➡ Keys

Paste it to the file

~/.aws/credentials
[default]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_SECRET_KEY

Connect to a bucket

s3-example.py
import boto3
s3 = boto3.resource(
    "s3",
    endpoint_url="https://s3.ice.ri.se",
)
bucket = s3.Bucket("do-test")

List all objects

for obj in bucket.objects.all():
    print(obj.key)

Download

bucket.download_file("images/test.jpg", "/tmp/test.jpg")

Upload

data = open('test.jpg', 'rb')
bucket.put_object(Key='files/file2.txt', Body=data)