Object Storage Service (OBS) provides a massive, secure and reliable data storage capabilities. Users can use OBS Console or OBS Browser to access and manage data stored in OBS from any computer connected to the Internet anytime and anywhere.
An OBS SDK is the encapsulation of RESTful APIs provided by OBS to simplify users interactions with their OBS objects.
In my previous article, i have covered the topic of mounting your Object Storage Bucket as a File System on your ECS Instance, which is for me the best solution to perform daily exchanges such as moving your local files and directories directly to the mounted Bucket without having to use the Cloud Provider’s Object Storage Console. However, the other alternative is to use the Object Storage Service (OBS) SDK to communicate with your S3 Bucket.
For this tutorial, i’ll be using the Flexible Engine Cloud Provider.So, i’ll focus on setting up the Flexible Engine Python SDK to access my Object Storage Bucket. However, the process is same if you’re using another Cloud Provider, you just need to get the appropriate SDK development package.
In order to get started, all what you need is a Flexible Engine account (or any Cloud Provider account that provides an Object Storage SDK development package), a Linux compute instance and of course an SSH access.
You also need to connect to your Cloud Provider account and setup up an IAM policy for your Object Storage Bucket :
- Allow read and write on your bucket
- Define and get your credentials (access key and secret key)
For more information about how to perform these steps , check out the Flexible Engine Documentation or your Cloud Provider Documentation.
Step 1: Install OBS SDK
- Download the OBS Python SDK development package by referring to Downloading the SDK.
- Decompress the development package to obtain folder
src(SDK source code), folder
examples(sample code), file
README.txt(feature description file of SDK versions), and file
log.conf(SDK log configuration file).
- Download and install setuptools.
- On the command-line interface (CLI), go to folder
srcunder the directory where the development package is decompressed.
- Run the
python setup.py intallcommand to install the SDK.
- After the installation, check whether a folder named
esdk_obs_python<versionId>-*.eggis generated in
lib/site-packageunder the Python installation directory.
Step 2: Configure Credentials and EndPoints
For Flexible Engine, you can find your
endpoint on the basic information provided in Object Storage Service console on your Flexible Engine account.
Once you’ve set the above parameters, you can construct your obsClient object that will allow you to perform different operations on your OBS bucket.
Now, you can use the examples provided in the examples folder in your SDK package to discover and test the different available methods. In order to get you started, you can test the following code that will allow you to create a bucket, get its location and storage informations and then delete it.
In order to move forward with your OBS SDK learning process, you can refer to the articles cited in the reference section.