Installation guide

Instead of relying on the CFResponse::isOK() method of the previous SDK to determine if an operation is
successful, the new SDK throws exceptions when the operation is not successful. Therefore, you can assume
success if there was no exception thrown, but you will need to add try...catch logic to your application code in
order to handle potential errors. The following is an example of how to handle the response of an Amazon
DynamoDB DescribeTable call in the new SDK:
$tableName = 'my-table';
try {
$result = $dynamoDb->describeTable(array('TableName' => $tableName));
printf('The provisioned throughput for table "%s" is %d RCUs and %d WCUs.',
$tableName,
$result->getPath('Table/ProvisionedThroughput/ReadCapacityUnits'),
$result->getPath('Table/ProvisionedThroughput/WriteCapacityUnits')
);
} catch (Aws\DynamoDb\Exception\DynamoDbException $e) {
echo "Error describing table {$tableName}";
}
You can get the Guzzle response object back from the command. This is helpful if you need to retrieve the status
code, additional data from the headers, or the raw response body.
$command = $dynamoDb->getCommand('DescribeTable', array('TableName' => $tableName));
$statusCode = $command->getResponse()->getStatusCode();
You can also get the response object and status code from the exception if one is thrown.
try {
$command = $dynamoDb->getCommand('DescribeTable', array(
'TableName' => $tableName
));
$statusCode = $command->getResponse()->getStatusCode();
} catch (Aws\DynamoDb\Exception\DynamoDbException $e) {
$statusCode = $e->getResponse()->getStatusCode();
}
Iterators
The SDK provides iterator classes that make it easier to traverse results from list and describe type operations.
Instead of having to code solutions that perform multiple requests in a loop and keep track of tokens or markers, the
iterator classes do that for you. You can simply foreach over the iterator:
$objects = $s3->getIterator('ListObjects', array(
'Bucket' => 'my-bucket-name'
));
foreach ($objects as $object) {
echo $object['Key'] . PHP_EOL;
}
Comparing Code Samples from Both SDKs
Example 1 - Amazon S3 ListParts Operation
From Version 1 of the SDK
<?php
require '/path/to/sdk.class.php';
require '/path/to/config.inc.php';
Migration Guide
12