Clients overview
AsyncAws has implemented the most popular API clients. On this page you find some installation instructions and a complete list of clients.
Install and configure¶
You install a client with Composer. Here is an example to install DynamoDb:
composer require async-aws/dynamo-db
To instantiate a DynamoDb client (or any other client) you could provide four arguments. All arguments are optional and sensible defaults are used.
use AsyncAws\Core\Configuration;
use AsyncAws\Core\Credentials\ConfigurationProvider;
use AsyncAws\Core\HttpClient\AwsHttpClientFactory;
use AsyncAws\DynamoDb\DynamoDbClient;
$config = Configuration::create([
'region' => 'eu-central-1',
]);
$credentialProvider = new ConfigurationProvider();
$httpClient = HttpClient::create(); // ... Instance of Symfony's HttpClientInterface
// Or, to enable automatic retries on top of your own HttpClient
// $httpClient = AwsHttpClientFactory::createRetryableClient($httpClient); T
$logger = // ... A PSR-3 logger
$dynamoDb = new DynamoDbClient($config, $credentialProvider, $httpClient, $logger);
A common way to instantiate a DynamoDb client might look like:
use AsyncAws\DynamoDb\DynamoDbClient;
$dynamoDb = new DynamoDbClient([
'region' => 'eu-central-1',
'accessKeyId' => 'AKIAIOSFODNN7EXAMPLE',
'accessKeySecret' => 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
]);
See section about authentication to learn more about different ways to authenticate.
Dependency injection container¶
If your application is using a dependency injection container, you may configure a client like:
Symfony
services:
AsyncAws\DynamoDb\DynamoDbClient:
arguments:
- region: "eu-central-1"
accessKeyId: "AKIAIOSFODNN7EXAMPLE"
accessKeySecret: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
- ~ # Use the default authentication providers
- "@http_client"
- "@logger"
If you are using Symfony you may ease configuration by install the Symfony Bundle.
Laravel
use Illuminate\Support\ServiceProvider;
use AsyncAws\DynamoDb\DynamoDbClient;
class AsyncAwsProvider extends ServiceProvider
{
public function register()
{
$this->app->bind(
DynamoDbClient::class,
function($app) {
return new DynamoDbClient([
'region' => 'eu-central-1',
'accessKeyId' => 'AKIAIOSFODNN7EXAMPLE',
'accessKeySecret' => 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
]);
}
);
}
}
Client factory¶
If you don't use dependency injection, you might be interested in the AwsClientFactory
that can be used to instantiate API clients.
use AsyncAws\Core\AwsClientFactory;
$factory = new AwsClientFactory([
'region' => 'eu-central-1',
'accessKeyId' => 'AKIAIOSFODNN7EXAMPLE',
'accessKeySecret' => 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
]);
$dynamoDb = $factory->dynamoDb();
$sqs = $factory->sqs();
Use¶
Every API client has functions that represent "operations" or API calls. Every such function takes an Input object (or array) as parameter and will return a Result. See the API client's class to learn what operations are supported and what the input and output are.
All Input objects for SQS is located in AsyncAws\Sqs\Input\*
and all Result objects are located in AsyncAws\Sqs\Result\*
.
Your IDE will also be helpful to discover function and how to use them. See example from PHPStorm:
All supported clients¶
Here is a list of supported clients. If there is a need for another client or a new operation, it can be automatically generated. See the contribution guide for more information.