If you are one of those people that like the Amazon PHP SDK but hate the fact that you need to download Guzzle, PSR-7 and every AWS API client to use it?
This is the library for you!
The official AWS PHP SDK is great. It is feature complete, it supports all Amazon APIs and is maintained by some really talented developers. This library is different. It is maintained by some dumb and lazy people.
The goals of this client are:
- Async first. Everything is asynchronous and responses are only downloaded if needed.
- Not feature complete. We are only covering the handful of services that are used by most people. We are not even covering all of those popular services.
- No frequent updates. Updates are great, but if changes are released multiple times every week you cannot keep up-to-date with the changelog. That is especially annoying when the changes are not related to services you use.
- Readable code. One should be able to read the code and follow the logic.
All APIs are located in different packages. To install SQS run
composer require async-aws/sqs
use AsyncAws\Sqs\SqsClient;
use AsyncAws\Sqs\Input\SendMessageRequest;
$sqsClient = new SqsClient([
'region' => 'eu-central-1',
'accessKeyId' => 'foo',
'accessKeySecret' => 'bar',
]);
// Call a client's method with an array
$result = $sqsClient->createQueue(['QueueName' => 'bar']);
// Request is automatically sent when reading the result
echo $result->getMessageId();
// You can also call a client's method with an input object
$input = new SendMessageRequest();
$input
->setQueueUrl('https://foo.com/bar')
->setMessageBody('foobar');
// Since we dont use a $result to get the return value,
// the HTTP request is sent automatically.
$sqsClient->sendMessage($input);
The secret ingredient in creating asynchronous first is not implemented in this library. It actually comes from the Symfony HTTP client. They have implemented all the cool async features that this AWS library just take advantage of.
Except for being a wrapper around Symfony's HTTP client and make sure we use the async features properly, we also handle authentication, exceptions and provide some response objects.
Some API Results are lists of items, like the result of S3Client::listObjectsV2()
.
These results implement \IteratorAggregate
and will automatically use AWS's pagination
API to make a new request to fetch the remaining resources in the list.
use AsyncAws\S3\S3Client;
use AsyncAws\S3\ValueObject\AwsObject;
use AsyncAws\S3\ValueObject\CommonPrefix;
$s3Client = new S3Client();
$result = $s3Client->listObjectsV2(['Bucket' => 'foo']);
/** @var AwsObject|CommonPrefix $file */
foreach($result as $file) {
if ($file instanceof AwsObject) {
echo $file->getKey();
}
}
Similar to Official AWS PHP SDK, AsyncAws provides waiters to let you wait until an long operation finished.
use AsyncAws\DynamoDb\DynamoDbClient;
$dbClient = new DynamoDbClient();
$dbClient->createTable([]);
// create a new table. It normally takes around 5 seconds to complete this action.
$dbClient->createTable(['TableName' => 'foobar', /* ...*/]);
$waiter = $dbClient->tableExists(['TableName' => 'foobar']);
echo $waiter->isSuccess(); // false
$waiter->wait();
echo $waiter->isSuccess(); // true
more information about waiters and hasers...
The main repository is not tagged and cannot be installed as a composer package.