
Connect AWS SDK for C++ to Polycloud distributed cloud storage.
Website at https://docs.aws.amazon.com/sdk-for-cpp.
Installation:
For Linux (Debian/Ubuntu-based), install the dependencies
$ sudo apt-get install libcurl4-openssl-dev libssl-dev uuid-dev zlib1g-dev libpulse-dev
$ git clone https://github.com/aws/aws-sdk-cpp.git
Install cmake (https://cmake.org/)
Build the SDK
$ sudo mkdir sdk_build
$ $ cd sdk_build
$ sudo cmake ../aws-sdk-cpp -D CMAKE_BUILD_TYPE=Release -D BUILD_ONLY="s3"
$ sudo make
$ sudo make install
Create your project
$ cd .. && mkdir my_example_project
Create a new file `my_example_project/CMakeLists.txt` with the following contents:
cmake_minimum_required(VERSION 3.2)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
project(my-example)
find_package(AWSSDK REQUIRED COMPONENTS s3)
add_executable(my-example my-example.cpp)
target_compile_features(my-example PUBLIC cxx_std_11)
target_link_libraries(my-example ${AWSSDK_LINK_LIBRARIES})
Create a new file `my_example_project/my-example.cpp` with the following contents (substituting `mybucket`, `<your access key>`. `<your secret>` with your information):
#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
#include <aws/core/auth/AWSCredentialsProviderChain.h>
>#include <aws/s3/model/ListObjectsRequest.h>
#include <aws/s3/model/Object.h>
int main(int argc, char** argv)
{
Aws::SDKOptions options;
Aws::InitAPI(options);
{
const Aws::String bucket_name = "mybucket";
Aws::Client::ClientConfiguration config;
config.endpointOverride = "https://polycloud.crowdapis.com";
config.region = "us-east-1";
Aws::S3::S3Client s3_client(Aws::Auth::AWSCredentials("<your access key>", "<your secret>"), config);
Aws::S3::Model::ListObjectsRequest objects_request;
objects_request.WithBucket(bucket_name);
auto list_objects_outcome = s3_client.ListObjects(objects_request);
if (list_objects_outcome.IsSuccess())
{
Aws::Vector<Aws::S3::Model::Object> object_list =
list_objects_outcome.GetResult().GetContents();
for (auto const &s3_object : object_list)
{
std::cout << s3_object.GetKey() << std::endl;
}
}
else
{
std::cout << "ListObjects error: " <<
list_objects_outcome.GetError().GetExceptionName() << " " <<
list_objects_outcome.GetError().GetMessage() << std::endl;
}
}
Aws::ShutdownAPI(options);
}
$ mkdir my_project_build && cd my_project_build
$ cmake -DAWSSDK_DIR=/usr/local/lib/cmake/AWSSDK -DBUILD_ONLY="s3" ../my_example_project/
$ make
$ ./my-example