Working with S3 and Cloud Storage in C++: AWS SDK for C++ Library

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Working with S3 and Cloud Storage in C++ using AWS SDK for C++



In modern application development, integration with cloud storage is increasingly required. Amazon S3 (Simple Storage Service) is the de facto standard for storing objects in the cloud. For the C++ language, the most powerful and supported solution is the official AWS SDK for C++ (aws-sdk-cpp) library. It provides a complete set of tools for working not only with S3, but also with MinIO, DigitalOcean Spaces, Yandex Object Storage, and any other S3-compatible storage.



Features and Benefits

  • Complete API — the library covers all S3 operations: creating/deleting buckets, uploading/downloading objects, version management, multi-threaded upload of large files.
  • Cross-platform — works on Linux, macOS, Windows, as well as mobile platforms (iOS, Android).
  • Asynchronous — built-in support for async/await via futures, allowing you to write efficient non-blocking code.
  • Compatibility with S3 alternatives — simply change the endpoint and credentials to switch from AWS S3 to MinIO or Yandex Object Storage.
  • Stream support — uploading/downloading data directly via std::iostream without storing the entire file in memory.


Installation and Setup

The library is distributed via vcpkg, Conan, or built from source. The recommended method is via vcpkg:

# Install vcpkg (if not already installed)git clone https://github.com/Microsoft/vcpkg.gitcd vcpkg./bootstrap-vcpkg.sh  # or bootstrap-vcpkg.bat for Windows

# Install SDK for S3./vcpkg install aws-sdk-cpp[s3]


In CMakeLists.txt, simply add:

find_package(AWSSDK REQUIRED COMPONENTS s3)target_link_libraries(your_target PRIVATE ${AWSSDK_LINK_LIBRARIES})


Basic Example: Uploading an Object to S3

Before starting, you need to configure credentials. The safest way is to use the ~/.aws/credentials file or the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.

#include <aws/core/Aws.h>#include <aws/s3/S3Client.h>#include <aws/s3/model/PutObjectRequest.h>#include <fstream>

int main() { Aws::SDKOptions options; Aws::InitAPI(options); { Aws::S3::S3Client s3_client;

const Aws::String bucket_name = "my-bucket"; const Aws::String object_key = "example.txt";

// Prepare request Aws::S3::Model::PutObjectRequest request; request.SetBucket(bucket_name); request.SetKey(object_key);

// Read file auto input_data = Aws::MakeShared<Aws::FStream>("tag", "local_file.txt", std::ios::in | std::ios::binary); request.SetBody(input_data);

// Execute request auto outcome = s3_client.PutObject(request); if (outcome.IsSuccess()) { std::cout << "File uploaded successfully!" << std::endl; } else { std::cerr << "Error: " << outcome.GetError().GetMessage() << std::endl; return 1; } } Aws::ShutdownAPI(options); return 0;}


Working with MinIO (Local S3 Storage)

For development and testing, it is convenient to use MinIO. To make the SDK work with MinIO, you need to change the endpoint and disable SSL verification (if HTTPS is not configured):

#include <aws/core/Aws.h>#include <aws/s3/S3Client.h>

int main() { Aws::SDKOptions options; Aws::InitAPI(options); { // Configure client for MinIO Aws::Client::ClientConfigura

Recommendations