C++ SDK

To use our service with the official AWS S3 SDK, you must set a few properties before establishing connection. We will show you how to do this in the following sections.

Installation

AWS CPP SDK recommends using CMake build environment, which is what we used for our example project. For this to work, we recommend installing CMake and the aws-sdk-cpp using your operation system package manager of choice.

Using the SDK

Follow the official guides: SDK Usage and Developer Guide. We will show you where to change the parameters.

First, let’s define your access parameters (key, secret, and endpoint).

1const char *secret_id = "YOUR_ACCESS_KEY";
2const char *secret_key = "YOUR_ACCESS_SECRET";
3const char *custom_endpoint = "s3.tebi.io";
4const Aws::Http::Scheme custom_endpoint_scheme = Scheme::HTTPS;

Before you create the s3_client object, make sure to either create a ClientConfiguration object, or extend any existing ClientConfiguration object you are already using by the following properties:

1// create config object
2ClientConfiguration config;
3config.scheme = custom_endpoint_scheme;
4config.endpointOverride = custom_endpoint;

Also, make sure to create an AWSCredentials object to handle the key and secret passed to the client:

1// create credential object
2Aws::Auth::AWSCredentials creds(secret_id, secret_key);

Now, make sure to pass the configuration and credentials to the S3 client:

1// create s3 client object
2Aws::S3::S3Client s3_client(creds, config);

With this, you can test the connection. The following code should list your available buckets on the Tebi platform:

 1// ~~~ functions  ~~~
 2Aws::S3::Model::ListBucketsOutcome outcome = s3_client.ListBuckets();
 3if (outcome.IsSuccess()) {
 4
 5  Aws::Vector<Aws::S3::Model::Bucket> bucket_list =
 6      outcome.GetResult().GetBuckets();
 7
 8  for (Aws::S3::Model::Bucket const &bucket : bucket_list) {
 9
10    std::cout << "Found the bucket: " << bucket.GetName() << std::endl;
11  }
12
13} else {
14  std::cout << "ListBuckets error: " << outcome.GetError().GetMessage()
15            << std::endl;
16}

For more examples, please refer to the official S3 samples repository over at GitHub.