1. Academy
  2. Object Store

How to connect to the Fuga Cloud ObjectStore using Python

Fuga supports Amazon S3 compatible object storage. To access the S3 storage you need an EC2 access key and secret key. These can be obtained using the OpenStack CLI or the OpenStack Keystone API (which is beyond the scope of this tutorial). Using the OpenStack CLI you can obtain the key pair using the ec2 credentials command as shown below.

openstack ec2 credentials list
+----------------------------------+----------------------------------+----------------------------------+----------------------------------+
| Access | Secret | Project ID | User ID |
+----------------------------------+----------------------------------+----------------------------------+----------------------------------+
| 99999999999999999999999999999999 | 99999999999999999999999999999999 | 99999999999999999999999999999999 | 99999999999999999999999999999999 |
+----------------------------------+----------------------------------+----------------------------------+----------------------------------+

When the list is empty a new key pair can be created using the 'openstack ec2 credentials create' command.

The S3 API can be found at:
  • AMS1: https://object.api.ams.fuga.cloud
  • AMS2: https://core.fuga.cloud:8080
Swift and S3 example can be found in the Dashboard -> API endpoints
Using the EC2 key pair and S3 URL the S3 object can now be accessed using any S3 client or by using one of the various libraries available. Below is a code example using the boto library in Python.
from boto.s3.key import Key
import boto
import boto.s3.connection

access_key = '99999999999999999999999999999999'
secret_key = '99999999999999999999999999999999'
filename = 'test.txt'

conn = boto.connect_s3(
aws_access_key_id = access_key,
aws_secret_access_key = secret_key,
host = 'object.api.fuga.cloud',
port = 443,
calling_format = boto.s3.connection.OrdinaryCallingFormat(),
)

bucket = conn.get_bucket('mybucket')

k = Key(bucket)
k.key = filename
k.set_contents_from_filename(filename)
k.make_public()

See also: