Installation guide

Amazon Simple Storage Service
This guide focuses on the AWS SDK for PHP client for Amazon Simple Storage Service. This guide assumes that
you have already downloaded and installed the AWS SDK for PHP. See Installation for more information on getting
started.
Creating a client
First you need to create a client object using one of the following techniques.
Factory method
The easiest way to get up and running quickly is to use the Aws\S3\S3Client::factory() method and provide
your credentials (key and secret).
use Aws\S3\S3Client;
$client = S3Client::factory(array(
'key' => '<aws access key>',
'secret' => '<aws secret key>'
));
You can provide your access keys like in the preceding example, or you can choose to omit them if you are using
AWS Identity and Access Management (IAM) roles for EC2 instances or credentials sourced from the
AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.
Service builder
A more robust way to connect to Amazon Simple Storage Service is through the service builder. This allows you to
specify credentials and other configuration settings in a configuration file. These settings can then be shared across
all clients so that you only have to specify your settings once.
use Aws\Common\Aws;
// Create a service builder using a configuration file
$aws = Aws::factory('/path/to/my_config.json');
// Get the client from the builder by namespace
$client = $aws->get('S3');
Creating a bucket
Now that we've created a client object, let's create a bucket. This bucket will be used throughout the remainder of
this guide.
$client->createBucket(array('Bucket' => 'mybucket'));
If you run the above code example unaltered, you'll probably trigger the following exception:
PHP Fatal error: Uncaught Aws\S3\Exception\BucketAlreadyExistsException: AWS Error
Code: BucketAlreadyExists, Status Code: 409, AWS Request ID: D94E6394791E98A4,
AWS Error Type: client, AWS Error Message: The requested bucket name is not
available. The bucket namespace is shared by all users of the system. Please select
a different name and try again.
This is because bucket names in Amazon S3 reside in a global namespace. You'll need to change the actual name
of the bucket used in the examples of this tutorial in order for them to work correctly.
Creating a bucket in another region
The above example creates a bucket in the standard US-EAST-1 region. You can change the bucket location by
passing a LocationConstraint value.
Amazon Simple Storage Service
102