Installation guide
However, the best way to provide temporary credentials is to use the createCredentials() helper method
included with the StsClient. This method extracts the data from an AWS STS result and creates the
Credentials object for you.
$result = $stsClient->getSessionToken();
$credentials = $stsClient->createCredentials($result);
$s3Client = S3Client::factory(array('credentials' => $credentials));
You can also use the same technique when setting credentials on an existing client object.
$credentials = $stsClient->createCredentials($stsClient->getSessionToken());
$s3Client->setCredentials($credentials);
For more information about why you might need to use temporary credentials in your application or project, see
Scenarios for Granting Temporary Access in the AWS STS documentation.
Configuring the SDK
The AWS SDK for PHP can be configured in many ways to suit your needs. This guide highlights the use of
configuration files with the service builder as well as individual client configuration options.
Configuration files
How configuration files work
When passing an array of parameters to the first argument of Aws\Common\Aws::factory(), the service builder
loads the default aws-config.php file and merges the array of shared parameters into the default configuration.
Excerpt from src/Aws/Common/Resources/aws-config.php:
<?php return array(
'class' => 'Aws\Common\Aws',
'services' => array(
'default_settings' => array(
'params' => array()
),
'autoscaling' => array(
'alias' => 'AutoScaling',
'extends' => 'default_settings',
'class' => 'Aws\AutoScaling\AutoScalingClient'
),
'cloudformation' => array(
'alias' => 'CloudFormation',
'extends' => 'default_settings',
'class' => 'Aws\CloudFormation\CloudFormationClient'
),
// ...
);
The aws-config.php file provides default configuration settings for associating client classes with service names.
This file tells the Aws\Common\Aws service builder which class to instantiate when you reference a client by name.
You can supply your credentials and other configuration settings to the service builder so that each client is
instantiated with those settings. To do this, pass an array of settings (including your key and secret) into the first
argument of Aws\Common\Aws::factory().
<?php
require 'vendor/autoload.php';
use Aws\Common\Aws;
Configuring the SDK
25