Yandex Cloud
Search
Contact UsTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI for business
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Yandex Object Storage
    • All tools
      • All SDKs
      • AWS SDK for Java
      • AWS SDK for JavaScript
      • AWS SDK for Python (boto)
      • AWS SDK for .NET
      • AWS SDK for C++
      • AWS SDK for PHP
      • AWS SDK for Go
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Bucket logs
  • Release notes
  • FAQ

In this article:

  • Getting started
  • Installation
  • Configuration
  • Code examples
  • CmakeLists
  • File EXAMPLE_FILE_S3.cpp
  1. Tools
  2. SDK
  3. AWS SDK for C++

AWS SDK for C++

Written by
Aleksei Kudakov
Updated at December 2, 2025
  • Getting started
  • Installation
  • Configuration
  • Code examples
    • CmakeLists
    • File EXAMPLE_FILE_S3.cpp

The AWS SDK for C++ is a software development kit for integration with AWS services.

Getting startedGetting started

  1. Create a service account.

  2. Assign to the service account the roles required for your project, e.g., storage.editor for a bucket (to work with a particular bucket) or a folder (to work with all buckets in this folder). For more information about roles, see Access management with Yandex Identity and Access Management.

    To work with objects in an encrypted bucket, a user or service account must have the following roles for the encryption key in addition to the storage.configurer role:

    • kms.keys.encrypter: To read the key, encrypt and upload objects.
    • kms.keys.decrypter: To read the key, decrypt and download objects.
    • kms.keys.encrypterDecrypter: This role includes the kms.keys.encrypter and kms.keys.decrypter permissions.

    For more information, see Key Management Service service roles.

  3. Create a static access key.

    As a result, you will get the static access key data. To authenticate in Object Storage, you will need the following:

    • key_id: Static access key ID
    • secret: Secret key

    Save key_id and secret: you will not be able to get the key value again.

Note

A service account is only allowed to view a list of buckets in the folder it was created in.

A service account can perform actions with objects in buckets that are created in folders different from the service account folder. To enable this, assign the service account roles for the appropriate folder or its bucket.

InstallationInstallation

To install the AWS SDK for C++, use the instructions posted on the developer's site.

ConfigurationConfiguration

  1. Create a directory to store the authentication data in and navigate to it:

    For macOS and Linux:

    mkdir ~/.aws/
    

    For Windows:

    mkdir C:\Users\<username>\.aws\
    
  2. In the .aws directory, create a file named credentials, copy the credentials you got earlier, and paste them into it:

    [default]
    aws_access_key_id = <static_key_ID>
    aws_secret_access_key = <secret_key>
    
  3. Create a file named config with the default region settings and copy the following information to it:

    [default]
    region = ru-central1
    endpoint_url = https://storage.yandexcloud.net
    

    Note

    Some apps designed to work with Amazon S3 do not allow you to specify the region; this is why Object Storage also accepts the value of the primary AWS region — the first row in the region table.

To access Object Storage, use the https://storage.yandexcloud.net endpoint.

Code examplesCode examples

See C++ code examples from the developer to interface with S3.

Below is an example of a simple program that illustrates the differences in settings for Yandex Object Storage.

CmakeListsCmakeLists

cmake_minimum_required(VERSION 3.8)
project("s3-examples")
set(CMAKE_CXX_STANDARD 20)

if(NOT BUILD_SHARED_LIBS)
    set(BUILD_SHARED_LIBS ON)
endif()

find_package(AWSSDK REQUIRED COMPONENTS s3 sts)

add_executable(EXAMPLE EXAMPLE_FILE_S3.cpp)

target_link_libraries(EXAMPLE ${AWSSDK_LINK_LIBRARIES}
${AWSSDK_PLATFORM_DEPS})

File EXAMPLE_FILE_S3.cppFile EXAMPLE_FILE_S3.cpp

#include <aws/core/Aws.h>
#include <aws/core/auth/AWSCredentialsProvider.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/model/Bucket.h>
#include <aws/s3/model/CreateBucketConfiguration.h>
#include <aws/s3/model/CreateBucketRequest.h>
#include <aws/s3/model/DeleteBucketRequest.h>
#include <aws/s3/model/ListObjectsRequest.h>
#include <aws/s3/model/PutObjectRequest.h>
#include <sys/stat.h>

#include <fstream>
#include <iostream>


// Finds the bucket and outputs its contents in the console
bool FindTheBucket(const Aws::S3::S3Client& s3Client, const Aws::String& bucketName)
{
    Aws::S3::Model::ListBucketsOutcome outcome = s3Client.ListBuckets();
    Aws::S3::Model::ListObjectsRequest request;

    if (outcome.IsSuccess()) {
        std::cout << "Looking for a bucket named '" << bucketName << "'..." << std::endl;

        Aws::Vector<Aws::S3::Model::Bucket> bucket_list = outcome.GetResult().GetBuckets();
        for (Aws::S3::Model::Bucket const& bucket : bucket_list) {
            if (bucket.GetName() == bucketName) {
                request.WithBucket(bucketName);
                std::cout << "Found the bucket." << std::endl << std::endl;

                auto outcome_obj = s3Client.ListObjects(request);
                std::cout << "Objects in bucket '" << bucketName << "':" << std::endl;

                Aws::Vector<Aws::S3::Model::Object> objects = outcome_obj.GetResult().GetContents();
                for (Aws::S3::Model::Object& object : objects) {
                    std::cout << object.GetKey() << std::endl;
                }
                return true;
            }
        }

        std::cout << "Could not find the bucket." << std::endl << std::endl;
        return true;
    } else {
        std::cout << "ListBuckets error: " << outcome.GetError().GetMessage() << std::endl;
    }
    return false;
}

int main(int argc, char* argv[])
{
    Aws::SDKOptions options;
    Aws::InitAPI(options);
    {

        // Settings section for using the AWS SDK with Object Storage
        Aws::Client::ClientConfiguration config;
        config.region = Aws::String("ru-central1");
        config.endpointOverride = Aws::String("storage.yandexcloud.net");

        Aws::String bucket_name = "bucket_name";
        // Initializing a connection
        Aws::S3::S3Client s3_client(config);

        FindTheBucket(s3_client, bucket_name);
    }
    Aws::ShutdownAPI(options);

    return 0;
}

Was the article helpful?

Previous
AWS SDK for .NET
Next
AWS SDK for PHP
© 2025 Direct Cursus Technology L.L.C.