Amazon S3 is one of the most popular cloud storage services available today. However, there are many other S3 compatible storage services that provide similar functionality. In this tutorial, we will explore how to use the boto3 wrapper for S3 compatible storage services.
Boto3 is a Python library that provides an interface to interact with Amazon Web Services (AWS). However, it can also be used to interact with S3 compatible storage services that follow the AWS S3 API. This allows you to use the same code to interact with multiple S3 compatible storage services.
Prerequisites
Before we begin, make sure you have the following:
- Python 3.x installed on your system
- Boto3 library installed (
pip install boto3
) - Access key ID and secret access key for your S3 compatible storage service
Code
Let’s start by looking at the code:
https://github.com/Gigillion/S3Python/blob/main/s3gigillion/s3gigillion.py
The above code defines a get_client
function that returns a Boto3 client object for S3 compatible storage. This function takes three arguments:
access_key_id
: The access key ID for your S3 compatible storage servicesecret_access_key
: The secret access key for your S3 compatible storage servicesession_token
(optional): The session token for your S3 compatible storage service
The get_client
function creates an instance of _GigillionStorage
and returns the storage
object from it. The _GigillionStorage
class is a helper class that initializes a Boto3 client object with the provided credentials and endpoint.
Usage
To use the get_client
function, simply import it and call it with your access key ID and secret access key:
from <module-name> import get_client
client = get_client('access-key-id', 'secret-access-key')
Replace <module-name>
with the name of the module containing the get_client
function. This will return a Boto3 client object that you can use to interact with your S3 compatible storage service.
Conclusion
In this tutorial, we explored how to use the boto3 wrapper for S3 compatible storage services. We saw how to create a Boto3 client object with the provided credentials and endpoint, and how to use it to interact with your S3 compatible storage service. By using the same code for multiple S3 compatible storage services, you can save time and effort in developing your applications.