Installation guide

Using Composer require '/path/to/vendor/autoload.php';
Using the Phar require '/path/to/aws.phar';
Using the Zip require '/path/to/aws-autoloader.php';
Using PEAR require 'AWSSDKforPHP/aws.phar';
For the remainder of this guide, we will show examples that use the Composer installation method. If you are using a
different installation method, then you can refer to this section and substitute in the proper code.
Creating a client object
To use the SDK, you first you need to instantiate a client object for the service you are using. We'll use the Amazon
Simple Storage Service (Amazon S3) client as an example. You can instantiate a client using two different
techniques.
Factory method
The easiest way to get up and running quickly is to use the web service client's factory() method and provide
your AWS credentials (e.g., key and secret).
<?php
// Include the SDK using the Composer autoloader
require 'vendor/autoload.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',
));
You can provide your credentials explicitly like in the preceding example, or you can choose to omit them if you are
relying on instance profile credentials provided via AWS Identity and Access Management (AWS IAM) roles for
EC2 instances, or environment credentials sourced from the AWS_ACCESS_KEY_ID and
AWS_SECRET_ACCESS_KEY environment variables. For more information about credentials, see Providing
Credentials to the SDK.
Note
Instance profile credentials and other temporary credentials generated by the AWS Security Token Service
(AWS STS) are not supported by every service. Please check if the service you are using supports temporary
credentials by reading AWS Services that Support AWS STS.
Depending on the service, you may also need to provide a region value to the factory() method. The region
value is used by the SDK to determine the regional endpoint to use to communicate with the service. Amazon S3
does not require you to provide a region, but other services like Amazon Elastic Compute Cloud (Amazon EC2) do.
You can specify a region and other configuration settings along with your credentials in the array argument that you
provide.
$ec2Client = \Aws\Ec2\Ec2Client::factory(array(
'key' => 'YOUR_AWS_ACCESS_KEY_ID',
'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY',
'region' => 'us-east-1',
));
To know if the service client you are using requires a region and to find out which regions are supported by the
client, please see the appropriate service-specific guide.
Getting Started Guide
5