Menu
AWS SDK for C++
Developer Guide

Using the AWS SDK for C++

To use the AWS SDK for C++, you should properly initialize it with Aws::InitAPI before creating service clients and using them. You should then shut down the SDK with Aws::ShutdownAPI.

Both of these functions take an instance of Aws::SDKOptions, which you can use to set additional run-time options for SDK calls.

Initializing and Shutting Down the SDK

A basic skeleton application looks like this:

Copy
#include <aws/core/Aws.h> int main(int argc, char** argv) { Aws::SDKOptions options; Aws::InitAPI(options); { // make your SDK calls here. } Aws::ShutdownAPI(options); return 0; }

Setting SDK options

The Aws::SDKOptions struct shown in Initializing and Shutting Down the SDK provides a number of options you can set. You should send the same options object to both Aws::InitAPI and Aws::ShutdownAPI.

A few examples:

  • Turn logging on using the default logger:

    Copy
    Aws::SDKOptions options options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info; Aws::InitAPI(options); { // make your SDK calls here. } Aws::ShutdownAPI(options);
  • Install a custom memory manager:

    Copy
    MyMemoryManager memoryManager; Aws::SDKOptions options options.memoryManagementOptions.memoryManager = &memoryManager; Aws::InitAPI(options); { // make your SDK calls here. } Aws::ShutdownAPI(options);
  • Override the default HTTP client factory:

    Copy
    Aws::SDKOptions options options.httpOptions.httpClientFactory_create_fn = [](){ return Aws::MakeShared<MyCustomHttpClientFactory>( "ALLOC_TAG", arg1); }; Aws::InitAPI(options); { // make your SDK calls here. } Aws::ShutdownAPI(options);

Note

httpOptions takes a closure instead of a std::shared_ptr. The SDK does this for all of its factory functions because the memory manager will not yet be installed at the time you will need to allocate this memory. Pass a closure to the SDK, and it will be called when it is safe to do so. This simplest way to do this is with a Lambda expression.

More Information

For further examples of AWS SDK for C++ application code, view the topics in the AWS SDK for C++ Code Examples section. Each example contains a link to the full source code on GitHub, which you can use as a starting point for your own applications.