General configuration using Aws::SDKOptions in the Amazon SDK for C++
The Aws::SDKOptions struct contains SDK configuration options.
Aws::SDKOptions focuses on general SDK configuration, whereas the ClientConfiguration struct focuses on
configuration of communicating with Amazon Web Services services.
An instance of Aws::SDKOptions is passed to the Aws::InitAPI and Aws::ShutdownAPI methods. The same
instance should be sent to both methods.
The following samples demonstrate some of the available options.
-
Turn logging on using the default logger
Aws::SDKOptions options; options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info; Aws::InitAPI(options); { // make your SDK calls here. } Aws::ShutdownAPI(options); -
Override the default HTTP client factory
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
httpOptionstakes a closure (also called an anonymous function or lambda expression) rather than astd::shared_ptr. Each of the SDK factory functions operates in this manner because at the time at which the factory memory allocation occurs, the memory manager has not yet been installed. By passing a closure to the method, the memory manager will be called to perform the memory allocation when it is safe to do so. A simple technique to accomplish this procedure is by using a Lambda expression. -
Use a global
SIGPIPEhandlerIf you build the SDK for C++ with curl and OpenSSL, you must specify a signal handler. If you don’t use your own custom signal handler, set
installSigPipeHandlertotrue.Aws::SDKOptions options; options.httpOptions.installSigPipeHandler = true; Aws::InitAPI(options); { // make your SDK calls here. } Aws::ShutdownAPI(options);When
installSigPipeHandleristrue, the SDK for C++ uses a handler that ignoresSIGPIPEsignals. For more information onSIGPIPE, see Operation Error Signalson the GNU Operating System website. For more information on the curl handler, see CURLOPT_NOSIGNAL explained on the curl website. The underlying libraries of curl and OpenSSL can send a
SIGPIPEsignal to notify when the remote side closes a connection. These signals must be handled by the application. For more information this curl functionality, see libcurl thread safetyon the curl website. This behavior is not automatically built-in to the SDK because signal handlers are global for each application and the library is a dependency for the SDK.