Installation guide

Working with modeled responses
The result of a performing an operation is what we refer to as a modeled response. Instead of returning the raw
XML or JSON data, the SDK will coerce the data into an associative array and normalize some aspects of the data
based on its knowledge of the specific service and the underlying response structure.
The actual value returned is a Model (Guzzle\Service\Resource\Model) object. The Model class is a part of
the SDK's underlying Guzzle library, but you do not need to know anything about Guzzle to use your operation
results. The Model object contains the data from the response and can be used like an array (e.g.,
$result['Table']). It also has convenience methods like get(), getPath(), and toArray(). The contents of
the modeled response depend on the operation that was executed and are documented in the API docs for each
operation (e.g., see the Returns section in the API docs for the DynamoDB DescribeTable operation).
$result = $dynamoDbClient->describeTable(array(
'TableName' => 'YourTableName',
));
// Get a specific value from the result
$table = $result['Table'];
if ($table && isset($table['TableStatus'])) {
echo $table['TableStatus'];
}
//> ACTIVE
// Get nested values from the result easily
echo $result->getPath('Table/TableStatus');
//> ACTIVE
// Convert the Model to a plain array
var_export($result->toArray());
//> array ( 'Table' => array ( 'AttributeDefinitions' => array ( ... ) ... ) ... )
To learn more about how to work with modeled responses, read the detailed guide to Modeled Responses.
Detecting and handling errors
When you preform an operation, and it succeeds, it will return a modeled response. If there was an error with the
request, then an exception is thrown. For this reason, you should use try/catch blocks around your operations if
you need to handle errors in your code. The SDK throws service-specific exceptions when a server-side error
occurs.
In the following example, the Aws\S3\S3Client is used. If there is an error, the exception thrown will be of the
type: Aws\S3\Exception\S3Exception.
try {
$s3Client->createBucket(array(
'Bucket' => 'my-bucket'
));
} catch (\Aws\S3\Exception\S3Exception $e) {
// The bucket couldn't be created
echo $e->getMessage();
}
Exceptions thrown by the SDK like this all extend the ServiceResponseException class (see the API docs),
which has some custom methods that might help you discover what went wrong.
Waiters
One of the higher-level abstractions provided by the SDK are waiters. Waiters help make it easier to work with
eventually consistent systems by providing an easy way to wait until a resource enters into a particular state by
polling the resource. You can find a list of the waiters supported by a client by viewing the API Documentation of a
service client. Any method with a name starting with "waitUntil" will create and invoke a waiter.
Getting Started Guide
7