DynamoDbClient.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace Aws\DynamoDb;
  3. use Aws\Api\Parser\Crc32ValidatingParser;
  4. use Aws\AwsClient;
  5. use Aws\ClientResolver;
  6. use Aws\Exception\AwsException;
  7. use Aws\HandlerList;
  8. use Aws\Middleware;
  9. use Aws\RetryMiddleware;
  10. use Aws\RetryMiddlewareV2;
  11. /**
  12. * This client is used to interact with the **Amazon DynamoDB** service.
  13. *
  14. * @method \Aws\Result batchGetItem(array $args = [])
  15. * @method \GuzzleHttp\Promise\Promise batchGetItemAsync(array $args = [])
  16. * @method \Aws\Result batchWriteItem(array $args = [])
  17. * @method \GuzzleHttp\Promise\Promise batchWriteItemAsync(array $args = [])
  18. * @method \Aws\Result createTable(array $args = [])
  19. * @method \GuzzleHttp\Promise\Promise createTableAsync(array $args = [])
  20. * @method \Aws\Result deleteItem(array $args = [])
  21. * @method \GuzzleHttp\Promise\Promise deleteItemAsync(array $args = [])
  22. * @method \Aws\Result deleteTable(array $args = [])
  23. * @method \GuzzleHttp\Promise\Promise deleteTableAsync(array $args = [])
  24. * @method \Aws\Result describeTable(array $args = [])
  25. * @method \GuzzleHttp\Promise\Promise describeTableAsync(array $args = [])
  26. * @method \Aws\Result getItem(array $args = [])
  27. * @method \GuzzleHttp\Promise\Promise getItemAsync(array $args = [])
  28. * @method \Aws\Result listTables(array $args = [])
  29. * @method \GuzzleHttp\Promise\Promise listTablesAsync(array $args = [])
  30. * @method \Aws\Result putItem(array $args = [])
  31. * @method \GuzzleHttp\Promise\Promise putItemAsync(array $args = [])
  32. * @method \Aws\Result query(array $args = [])
  33. * @method \GuzzleHttp\Promise\Promise queryAsync(array $args = [])
  34. * @method \Aws\Result scan(array $args = [])
  35. * @method \GuzzleHttp\Promise\Promise scanAsync(array $args = [])
  36. * @method \Aws\Result updateItem(array $args = [])
  37. * @method \GuzzleHttp\Promise\Promise updateItemAsync(array $args = [])
  38. * @method \Aws\Result updateTable(array $args = [])
  39. * @method \GuzzleHttp\Promise\Promise updateTableAsync(array $args = [])
  40. * @method \Aws\Result batchExecuteStatement(array $args = []) (supported in versions 2012-08-10)
  41. * @method \GuzzleHttp\Promise\Promise batchExecuteStatementAsync(array $args = []) (supported in versions 2012-08-10)
  42. * @method \Aws\Result createBackup(array $args = []) (supported in versions 2012-08-10)
  43. * @method \GuzzleHttp\Promise\Promise createBackupAsync(array $args = []) (supported in versions 2012-08-10)
  44. * @method \Aws\Result createGlobalTable(array $args = []) (supported in versions 2012-08-10)
  45. * @method \GuzzleHttp\Promise\Promise createGlobalTableAsync(array $args = []) (supported in versions 2012-08-10)
  46. * @method \Aws\Result deleteBackup(array $args = []) (supported in versions 2012-08-10)
  47. * @method \GuzzleHttp\Promise\Promise deleteBackupAsync(array $args = []) (supported in versions 2012-08-10)
  48. * @method \Aws\Result describeBackup(array $args = []) (supported in versions 2012-08-10)
  49. * @method \GuzzleHttp\Promise\Promise describeBackupAsync(array $args = []) (supported in versions 2012-08-10)
  50. * @method \Aws\Result describeContinuousBackups(array $args = []) (supported in versions 2012-08-10)
  51. * @method \GuzzleHttp\Promise\Promise describeContinuousBackupsAsync(array $args = []) (supported in versions 2012-08-10)
  52. * @method \Aws\Result describeContributorInsights(array $args = []) (supported in versions 2012-08-10)
  53. * @method \GuzzleHttp\Promise\Promise describeContributorInsightsAsync(array $args = []) (supported in versions 2012-08-10)
  54. * @method \Aws\Result describeEndpoints(array $args = []) (supported in versions 2012-08-10)
  55. * @method \GuzzleHttp\Promise\Promise describeEndpointsAsync(array $args = []) (supported in versions 2012-08-10)
  56. * @method \Aws\Result describeExport(array $args = []) (supported in versions 2012-08-10)
  57. * @method \GuzzleHttp\Promise\Promise describeExportAsync(array $args = []) (supported in versions 2012-08-10)
  58. * @method \Aws\Result describeGlobalTable(array $args = []) (supported in versions 2012-08-10)
  59. * @method \GuzzleHttp\Promise\Promise describeGlobalTableAsync(array $args = []) (supported in versions 2012-08-10)
  60. * @method \Aws\Result describeGlobalTableSettings(array $args = []) (supported in versions 2012-08-10)
  61. * @method \GuzzleHttp\Promise\Promise describeGlobalTableSettingsAsync(array $args = []) (supported in versions 2012-08-10)
  62. * @method \Aws\Result describeKinesisStreamingDestination(array $args = []) (supported in versions 2012-08-10)
  63. * @method \GuzzleHttp\Promise\Promise describeKinesisStreamingDestinationAsync(array $args = []) (supported in versions 2012-08-10)
  64. * @method \Aws\Result describeLimits(array $args = []) (supported in versions 2012-08-10)
  65. * @method \GuzzleHttp\Promise\Promise describeLimitsAsync(array $args = []) (supported in versions 2012-08-10)
  66. * @method \Aws\Result describeTableReplicaAutoScaling(array $args = []) (supported in versions 2012-08-10)
  67. * @method \GuzzleHttp\Promise\Promise describeTableReplicaAutoScalingAsync(array $args = []) (supported in versions 2012-08-10)
  68. * @method \Aws\Result describeTimeToLive(array $args = []) (supported in versions 2012-08-10)
  69. * @method \GuzzleHttp\Promise\Promise describeTimeToLiveAsync(array $args = []) (supported in versions 2012-08-10)
  70. * @method \Aws\Result disableKinesisStreamingDestination(array $args = []) (supported in versions 2012-08-10)
  71. * @method \GuzzleHttp\Promise\Promise disableKinesisStreamingDestinationAsync(array $args = []) (supported in versions 2012-08-10)
  72. * @method \Aws\Result enableKinesisStreamingDestination(array $args = []) (supported in versions 2012-08-10)
  73. * @method \GuzzleHttp\Promise\Promise enableKinesisStreamingDestinationAsync(array $args = []) (supported in versions 2012-08-10)
  74. * @method \Aws\Result executeStatement(array $args = []) (supported in versions 2012-08-10)
  75. * @method \GuzzleHttp\Promise\Promise executeStatementAsync(array $args = []) (supported in versions 2012-08-10)
  76. * @method \Aws\Result executeTransaction(array $args = []) (supported in versions 2012-08-10)
  77. * @method \GuzzleHttp\Promise\Promise executeTransactionAsync(array $args = []) (supported in versions 2012-08-10)
  78. * @method \Aws\Result exportTableToPointInTime(array $args = []) (supported in versions 2012-08-10)
  79. * @method \GuzzleHttp\Promise\Promise exportTableToPointInTimeAsync(array $args = []) (supported in versions 2012-08-10)
  80. * @method \Aws\Result listBackups(array $args = []) (supported in versions 2012-08-10)
  81. * @method \GuzzleHttp\Promise\Promise listBackupsAsync(array $args = []) (supported in versions 2012-08-10)
  82. * @method \Aws\Result listContributorInsights(array $args = []) (supported in versions 2012-08-10)
  83. * @method \GuzzleHttp\Promise\Promise listContributorInsightsAsync(array $args = []) (supported in versions 2012-08-10)
  84. * @method \Aws\Result listExports(array $args = []) (supported in versions 2012-08-10)
  85. * @method \GuzzleHttp\Promise\Promise listExportsAsync(array $args = []) (supported in versions 2012-08-10)
  86. * @method \Aws\Result listGlobalTables(array $args = []) (supported in versions 2012-08-10)
  87. * @method \GuzzleHttp\Promise\Promise listGlobalTablesAsync(array $args = []) (supported in versions 2012-08-10)
  88. * @method \Aws\Result listTagsOfResource(array $args = []) (supported in versions 2012-08-10)
  89. * @method \GuzzleHttp\Promise\Promise listTagsOfResourceAsync(array $args = []) (supported in versions 2012-08-10)
  90. * @method \Aws\Result restoreTableFromBackup(array $args = []) (supported in versions 2012-08-10)
  91. * @method \GuzzleHttp\Promise\Promise restoreTableFromBackupAsync(array $args = []) (supported in versions 2012-08-10)
  92. * @method \Aws\Result restoreTableToPointInTime(array $args = []) (supported in versions 2012-08-10)
  93. * @method \GuzzleHttp\Promise\Promise restoreTableToPointInTimeAsync(array $args = []) (supported in versions 2012-08-10)
  94. * @method \Aws\Result tagResource(array $args = []) (supported in versions 2012-08-10)
  95. * @method \GuzzleHttp\Promise\Promise tagResourceAsync(array $args = []) (supported in versions 2012-08-10)
  96. * @method \Aws\Result transactGetItems(array $args = []) (supported in versions 2012-08-10)
  97. * @method \GuzzleHttp\Promise\Promise transactGetItemsAsync(array $args = []) (supported in versions 2012-08-10)
  98. * @method \Aws\Result transactWriteItems(array $args = []) (supported in versions 2012-08-10)
  99. * @method \GuzzleHttp\Promise\Promise transactWriteItemsAsync(array $args = []) (supported in versions 2012-08-10)
  100. * @method \Aws\Result untagResource(array $args = []) (supported in versions 2012-08-10)
  101. * @method \GuzzleHttp\Promise\Promise untagResourceAsync(array $args = []) (supported in versions 2012-08-10)
  102. * @method \Aws\Result updateContinuousBackups(array $args = []) (supported in versions 2012-08-10)
  103. * @method \GuzzleHttp\Promise\Promise updateContinuousBackupsAsync(array $args = []) (supported in versions 2012-08-10)
  104. * @method \Aws\Result updateContributorInsights(array $args = []) (supported in versions 2012-08-10)
  105. * @method \GuzzleHttp\Promise\Promise updateContributorInsightsAsync(array $args = []) (supported in versions 2012-08-10)
  106. * @method \Aws\Result updateGlobalTable(array $args = []) (supported in versions 2012-08-10)
  107. * @method \GuzzleHttp\Promise\Promise updateGlobalTableAsync(array $args = []) (supported in versions 2012-08-10)
  108. * @method \Aws\Result updateGlobalTableSettings(array $args = []) (supported in versions 2012-08-10)
  109. * @method \GuzzleHttp\Promise\Promise updateGlobalTableSettingsAsync(array $args = []) (supported in versions 2012-08-10)
  110. * @method \Aws\Result updateTableReplicaAutoScaling(array $args = []) (supported in versions 2012-08-10)
  111. * @method \GuzzleHttp\Promise\Promise updateTableReplicaAutoScalingAsync(array $args = []) (supported in versions 2012-08-10)
  112. * @method \Aws\Result updateTimeToLive(array $args = []) (supported in versions 2012-08-10)
  113. * @method \GuzzleHttp\Promise\Promise updateTimeToLiveAsync(array $args = []) (supported in versions 2012-08-10)
  114. */
  115. class DynamoDbClient extends AwsClient
  116. {
  117. public static function getArguments()
  118. {
  119. $args = parent::getArguments();
  120. $args['retries']['default'] = 10;
  121. $args['retries']['fn'] = [__CLASS__, '_applyRetryConfig'];
  122. $args['api_provider']['fn'] = [__CLASS__, '_applyApiProvider'];
  123. return $args;
  124. }
  125. /**
  126. * Convenience method for instantiating and registering the DynamoDB
  127. * Session handler with this DynamoDB client object.
  128. *
  129. * @param array $config Array of options for the session handler factory
  130. *
  131. * @return SessionHandler
  132. */
  133. public function registerSessionHandler(array $config = [])
  134. {
  135. $handler = SessionHandler::fromClient($this, $config);
  136. $handler->register();
  137. return $handler;
  138. }
  139. /** @internal */
  140. public static function _applyRetryConfig($value, array &$args, HandlerList $list)
  141. {
  142. if ($value) {
  143. $config = \Aws\Retry\ConfigurationProvider::unwrap($value);
  144. if ($config->getMode() === 'legacy') {
  145. $list->appendSign(
  146. Middleware::retry(
  147. RetryMiddleware::createDefaultDecider(
  148. $config->getMaxAttempts() - 1,
  149. ['error_codes' => ['TransactionInProgressException']]
  150. ),
  151. function ($retries) {
  152. return $retries
  153. ? RetryMiddleware::exponentialDelay($retries) / 2
  154. : 0;
  155. },
  156. isset($args['stats']['retries'])
  157. ? (bool)$args['stats']['retries']
  158. : false
  159. ),
  160. 'retry'
  161. );
  162. } else {
  163. $list->appendSign(
  164. RetryMiddlewareV2::wrap(
  165. $config,
  166. [
  167. 'collect_stats' => $args['stats']['retries'],
  168. 'transient_error_codes' => ['TransactionInProgressException']
  169. ]
  170. ),
  171. 'retry'
  172. );
  173. }
  174. }
  175. }
  176. /** @internal */
  177. public static function _applyApiProvider($value, array &$args, HandlerList $list)
  178. {
  179. ClientResolver::_apply_api_provider($value, $args);
  180. $args['parser'] = new Crc32ValidatingParser($args['parser']);
  181. }
  182. }