Installation guide
This will automatically set up the service clients from Version 1 of the SDK making them accessible through the
service builder by keys such as v1.s3 and v1.cloudformation. Here is an example configuration file that
includes referencing the Version 1 of the SDK:
<?php return array(
'includes' => array('_sdk1'),
'services' => array(
'default_settings' => array(
'params' => array(
'key' => 'your-aws-access-key-id',
'secret' => 'your-aws-secret-access-key',
'region' => 'us-west-2'
)
)
)
);
Your code must instantiate the service builder through its factory method by passing in the path of the configuration
file. Your code then retrieves instances of the specific service clients from the returned builder object.
use Aws\Common\Aws;
// Instantiate the service builder
$aws = Aws::factory('/path/to/your/config.php');
// Instantiate S3 clients via the service builder
$s3v1 = $aws->get('v1.s3'); // All Version 1 clients are prefixed with "v1."
$s3v2 = $aws->get('s3');
Instantiating Clients via Client Factories
Your code can instantiate service clients using their respective factory() methods by passing in an array of
configuration data, including your credentials. The factory() will work for clients in either versions of the SDK.
use Aws\S3\S3Client;
// Create an array of configuration options
$config = array(
'key' => 'your-aws-access-key-id',
'secret' => 'your-aws-secret-access-key',
);
// Instantiate Amazon S3 clients from both SDKs via their factory methods
$s3v1 = AmazonS3::factory($config);
$s3v2 = S3Client::factory($config);
Optionally, you could alias the classes to make it clearer which version of the SDK they are from.
use AmazonS3 as S3ClientV1;
use Aws\S3\S3Client as S3ClientV2;
$config = array(
'key' => 'your-aws-access-key-id',
'secret' => 'your-aws-secret-access-key',
);
$s3v1 = S3ClientV1::factory($config);
$s3v2 = S3ClientV2::factory($config);
Complete Examples
The following two examples fully demonstrate including, configuring, instantiating, and using both SDKs
side-by-side. These examples adopt the recommended practices of using Composer and the service builder.
Side-by-side Guide
17