How to integrate the AWS SDK with other HTTP clients

The http_handler option is used to integrate the SDK with other HTTP clients. An http_handler option is a function that accepts a Psr\Http\Message\RequestInterface object and an array of http options applied to the command, and returns a GuzzleHttp\Promise\PromiseInterface object that is fulfilled with a Psr\Http\Message\ResponseInterface object or rejected with an array of the following exception data:

  • exception – (\Exception) the exception that was encountered.
  • response – (Psr\Http\Message\ResponseInterface) the response that was received (if any).
  • connection_error – (bool) set to true to mark the error as a connection error. Setting this value to true also allows the SDK to automatically retry the operation, if needed.

The SDK automatically converts the given http_handler into a normal handler option by wrapping the provided http_handler with a Aws\WrappedHttpHandler object.

By default, the SDK uses Guzzle as its HTTP handler. You can supply a different HTTP handler here, or provide a Guzzle client with your own custom defined options.

Setting TLS version

One use case is to set the TLS version used by Guzzle with Curl, assuming Curl is installed in your environment. Note the Curl version constraints for what version of TLS is supported. By default, the latest version is used. If the TLS version is explicitly set, and the remote server doesn’t support this version, it will produce an error instead of using an earlier TLS version.

You can determine the TLS version being used for a given client operation by setting the debug client option to true and examining the SSL connection output. That line might look something like: SSL connection using TLSv1.2

Example setting TLS 1.2 with Guzzle 6:

use Aws\DynamoDb\DynamoDbClient; 
use Aws\Handler\GuzzleV6\GuzzleHandler; 
use GuzzleHttp\Client; 
$handler = new GuzzleHandler(
  new Client([ 
      'curl' => [ 
       ]]) ); 

$client = new DynamoDbClient(
           'region'  => 'us-west-2',
            'version' => 'latest',
            'http_handler' => $handler ]);


The http_handler option supersedes any provided handler option.

Leave a Comment

Your email address will not be published. Required fields are marked *