Did you know that you can navigate the posts by swiping left and right?

[S3] C++ AWS SDK 이용하기 (Credential, Endpoint 설정)

27 Dec 2022 . category: s3 . Comments
#s3

#include <aws/core/Aws.h>
#include <aws/core/auth/AWSCredentials.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/model/Bucket.h>

int main(int argc, char **argv) {

    Aws::SDKOptions options;
    options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Debug;

    //The AWS SDK for C++ must be initialized by calling Aws::InitAPI.
    Aws::InitAPI(options); 
    {
        // radosgw-admin user info --uid=admin
        Aws::Auth::AWSCredentials credentials;
        credentials.SetAWSAccessKeyId(Aws::String(ACCESS_KEY));
        credentials.SetAWSSecretKey(Aws::String(SECRET_KEY));

        Aws::Client::ClientConfiguration clientConfig;
        clientConfig.endpointOverride = "111.222.111.222:12345";
        clientConfig.scheme = Aws::Http::Scheme::HTTP;
        clientConfig.verifySSL = false;

        Aws::S3::S3Client client = Aws::S3::S3Client(credentials, clientConfig, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, false);

        auto outcome = client.ListBuckets();
        if (outcome.IsSuccess()) {
            std::cout << "Found " << outcome.GetResult().GetBuckets().size() << " buckets\n";
            for (auto&& b : outcome.GetResult().GetBuckets()) {
                std::cout << b.GetName() << std::endl;
            }
        }
        else {
            std::cout << "Failed with error: " << outcome.GetError() << std::endl;
        }
    }

    //Before the application terminates, the SDK must be shut down. 
    Aws::ShutdownAPI(options);
    return 0;
}

이렇게 Aws::Auth::AWSCredentials 에 Accesskey, SecretKey 를 넣고, Aws::Client::ClientConfiguration Endpoint 를 잘 설정해서 S3Client 객체를 생성하면 된다.

여기서 주의할 점은, Aws::Client::ClientConfiguration 의 멤버 변수의 proxyScheme 등과 헷갈리면 안된다는 것이다.


Me

Coding Future, Decoding Society.