Installation guide
The SDK provides a service builder that can be used to share configuration values across multiple clients. The
service builder allows you to specify default configuration values (e.g., credentials and regions) that are used by
every client. The service builder is configured using either JSON configuration files or PHP scripts that return an
array.
The following is an example of a configuration script that returns an array of configuration data that can be used by
the service builder:
<?php
return array(
// Bootstrap the configuration file with AWS specific features
'includes' => array('_aws'),
'services' => array(
// All AWS clients extend from 'default_settings'. Here we are
// overriding 'default_settings' with our default credentials and
// providing a default region setting.
'default_settings' => array(
'params' => array(
'key' => 'YOUR_AWS_ACCESS_KEY_ID',
'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY',
'region' => 'us-west-1'
)
)
)
);
After creating and saving the configuration file, you need to instantiate a service builder.
<?php
use Aws\Common\Aws;
// Create the AWS service builder, providing the path to the config file
$aws = Aws::factory('/path/to/custom/config.php');
At this point, you can now create clients using the get() method of the Aws object:
$s3Client = $aws->get('s3');
Passing credentials into a client factory method
A simple way to specify your credentials is by injecting them directly into the factory method when instantiating the
client object.
<?php
use Aws\S3\S3Client;
// Instantiate the S3 client with your AWS credentials
$s3Client = S3Client::factory(array(
'key' => 'YOUR_AWS_ACCESS_KEY_ID',
'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY',
));
In some cases, you may already have an instance of a Credentials object. You can use this instead of
specifying your access keys separately.
<?php
use Aws\S3\S3Client;
use Aws\Common\Credentials\Credentials;
$credentials = new Credentials('YOUR_ACCESS_KEY', 'YOUR_SECRET_KEY');
Providing Credentials to the SDK
22