Class WriteRequestBatch
The WriteRequestBatch is an object that is capable of efficiently sending DynamoDB BatchWriteItem requests from queued up put and delete item requests. requests. The batch attempts to send the requests with the fewest requests to DynamoDB as possible and also re-queues any unprocessed items to ensure that all items are sent.
Methods Summary
-
__construct ( Aws\DynamoDb\DynamoDbClient $client, array $config = [] )
Creates a WriteRequestBatch object that is capable of efficiently sending DynamoDB BatchWriteItem requests from queued up Put and Delete requests.
-
put ( array $item, string|null $table = null )
Adds a put item request to the batch.
-
delete ( array $key, string|null $table = null )
Adds a delete item request to the batch.
-
flush ( bool $untilEmpty = true )
Flushes the batch by combining all the queued put and delete requests into BatchWriteItem commands and executing them. Unprocessed items are automatically re-queued.
Methods Details
__construct (
Aws\DynamoDb\DynamoDbClient
$client,
array
$config = []
)
Creates a WriteRequestBatch object that is capable of efficiently sending DynamoDB BatchWriteItem requests from queued up Put and Delete requests.
Parameters
Aws\DynamoDb\DynamoDbClient |
$client | DynamoDB client used to send batches. |
array | $config = [] | Batch configuration options. - table: (string) DynamoDB table used by the batch, this can be overridden for each individual put() or delete() call. - batch_size: (int) The size of each batch (default: 25). The batch size must be between 2 and 25. If you are sending batches of large items, you may consider lowering the batch size, otherwise, you should use 25. - pool_size: (int) This number dictates how many BatchWriteItem requests you would like to do in parallel. For example, if the "batch_size" is 25, and "pool_size" is 3, then you would send 3 BatchWriteItem requests at a time, each with 25 items. Please keep your throughput in mind when choosing the "pool_size" option. - autoflush: (bool) This option allows the batch to automatically flush once there are enough items (i.e., "batch_size" * "pool_size") in the queue. This defaults to true, so you must set this to false to stop autoflush. - before: (callable) Executed before every BatchWriteItem operation. It should accept an \Aws\CommandInterface object as its argument. - error: Executed if an error was encountered executing a, BatchWriteItem operation, otherwise errors are ignored. It should accept an \Aws\Exception\AwsException as its argument. |
Exceptions
InvalidArgumentException if the batch size is not between 2 and 25. |
put ( array $item, string|null $table = null )
Adds a put item request to the batch.
Parameters
array | $item | Data for an item to put. Format: [ 'attribute1' => ['type' => 'value'], 'attribute2' => ['type' => 'value'], ... ] |
string|null | $table = null | The name of the table. This must be specified unless the "table" option was provided in the config of the WriteRequestBatch. |
Returns
$this |
delete ( array $key, string|null $table = null )
Adds a delete item request to the batch.
Parameters
array | $key | Key of an item to delete. Format: [ 'key1' => ['type' => 'value'], ... ] |
string|null | $table = null | The name of the table. This must be specified unless the "table" option was provided in the config of the WriteRequestBatch. |
Returns
$this |
flush ( boolean $untilEmpty = true )
Flushes the batch by combining all the queued put and delete requests into BatchWriteItem commands and executing them. Unprocessed items are automatically re-queued.
Parameters
boolean | $untilEmpty = true | If true, flushing will continue until the queue is completely empty. This will make sure that unprocessed items are all eventually sent. |
Returns
$this |