Installation guide
Example 1 - Dual Amazon S3 Clients
This example demonstrates using an Amazon S3 client from the AWS SDK for PHP working side-by-side with an
Amazon S3 client from the first PHP SDK.
<?php
require 'vendor/autoload.php';
$aws = Aws\Common\Aws::factory('/path/to/config.json');
$s3v1 = $aws->get('v1.s3');
$s3v2 = $aws->get('s3');
echo "ListBuckets with SDK Version 1:\n";
echo "-------------------------------\n";
$response = $s3v1->listBuckets();
if ($response->isOK()) {
foreach ($response->body->Buckets->Bucket as $bucket) {
echo "- {$bucket->Name}\n";
}
} else {
echo "Request failed.\n";
}
echo "\n";
echo "ListBuckets with SDK Version 2:\n";
echo "-------------------------------\n";
try {
$result = $s3v2->listBuckets();
foreach ($result['Buckets'] as $bucket) {
echo "- {$bucket['Name']}\n";
}
} catch (Aws\S3\Exception\S3Exception $e) {
echo "Request failed.\n";
}
echo "\n";
Example 2 - Amazon DynamoDB and Amazon SNS Clients
This example shows how the AWS SDK for PHP DynamoDB client works together with the SNS client from the
original SDK. For this example, an ice cream parlor publishes a daily message (via SNS) containing its "flavors of
the day" to subscribers. First, it retrieves the flavors of the day from its DynamoDB database using the AWS SDK for
PHP DynamoDB client. It then uses the SNS client from the first SDK to publish a message to its SNS topic.
<?php
require 'vendor/autoload.php';
$aws = Aws\Common\Aws::factory('/path/to/config.php');
// Instantiate the clients
$ddb = $aws->get('dynamodb');
$sns = $aws->get('v1.sns');
$sns->set_region(AmazonSNS::REGION_US_W2);
// Get today's flavors from DynamoDB using Version 2 of the SDK
$date = new DateTime();
$flavors = $ddb->getItem(array(
'TableName' => 'flavors-of-the-day',
'Key' => array(
'HashKeyElement' => array('N' => $date->format('n')),
Side-by-side Guide
18