DynamoDbClient.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 deleteResourcePolicy(array $args = []) (supported in versions 2012-08-10)
  49. * @method \GuzzleHttp\Promise\Promise deleteResourcePolicyAsync(array $args = []) (supported in versions 2012-08-10)
  50. * @method \Aws\Result describeBackup(array $args = []) (supported in versions 2012-08-10)
  51. * @method \GuzzleHttp\Promise\Promise describeBackupAsync(array $args = []) (supported in versions 2012-08-10)
  52. * @method \Aws\Result describeContinuousBackups(array $args = []) (supported in versions 2012-08-10)
  53. * @method \GuzzleHttp\Promise\Promise describeContinuousBackupsAsync(array $args = []) (supported in versions 2012-08-10)
  54. * @method \Aws\Result describeContributorInsights(array $args = []) (supported in versions 2012-08-10)
  55. * @method \GuzzleHttp\Promise\Promise describeContributorInsightsAsync(array $args = []) (supported in versions 2012-08-10)
  56. * @method \Aws\Result describeEndpoints(array $args = []) (supported in versions 2012-08-10)
  57. * @method \GuzzleHttp\Promise\Promise describeEndpointsAsync(array $args = []) (supported in versions 2012-08-10)
  58. * @method \Aws\Result describeExport(array $args = []) (supported in versions 2012-08-10)
  59. * @method \GuzzleHttp\Promise\Promise describeExportAsync(array $args = []) (supported in versions 2012-08-10)
  60. * @method \Aws\Result describeGlobalTable(array $args = []) (supported in versions 2012-08-10)
  61. * @method \GuzzleHttp\Promise\Promise describeGlobalTableAsync(array $args = []) (supported in versions 2012-08-10)
  62. * @method \Aws\Result describeGlobalTableSettings(array $args = []) (supported in versions 2012-08-10)
  63. * @method \GuzzleHttp\Promise\Promise describeGlobalTableSettingsAsync(array $args = []) (supported in versions 2012-08-10)
  64. * @method \Aws\Result describeImport(array $args = []) (supported in versions 2012-08-10)
  65. * @method \GuzzleHttp\Promise\Promise describeImportAsync(array $args = []) (supported in versions 2012-08-10)
  66. * @method \Aws\Result describeKinesisStreamingDestination(array $args = []) (supported in versions 2012-08-10)
  67. * @method \GuzzleHttp\Promise\Promise describeKinesisStreamingDestinationAsync(array $args = []) (supported in versions 2012-08-10)
  68. * @method \Aws\Result describeLimits(array $args = []) (supported in versions 2012-08-10)
  69. * @method \GuzzleHttp\Promise\Promise describeLimitsAsync(array $args = []) (supported in versions 2012-08-10)
  70. * @method \Aws\Result describeTableReplicaAutoScaling(array $args = []) (supported in versions 2012-08-10)
  71. * @method \GuzzleHttp\Promise\Promise describeTableReplicaAutoScalingAsync(array $args = []) (supported in versions 2012-08-10)
  72. * @method \Aws\Result describeTimeToLive(array $args = []) (supported in versions 2012-08-10)
  73. * @method \GuzzleHttp\Promise\Promise describeTimeToLiveAsync(array $args = []) (supported in versions 2012-08-10)
  74. * @method \Aws\Result disableKinesisStreamingDestination(array $args = []) (supported in versions 2012-08-10)
  75. * @method \GuzzleHttp\Promise\Promise disableKinesisStreamingDestinationAsync(array $args = []) (supported in versions 2012-08-10)
  76. * @method \Aws\Result enableKinesisStreamingDestination(array $args = []) (supported in versions 2012-08-10)
  77. * @method \GuzzleHttp\Promise\Promise enableKinesisStreamingDestinationAsync(array $args = []) (supported in versions 2012-08-10)
  78. * @method \Aws\Result executeStatement(array $args = []) (supported in versions 2012-08-10)
  79. * @method \GuzzleHttp\Promise\Promise executeStatementAsync(array $args = []) (supported in versions 2012-08-10)
  80. * @method \Aws\Result executeTransaction(array $args = []) (supported in versions 2012-08-10)
  81. * @method \GuzzleHttp\Promise\Promise executeTransactionAsync(array $args = []) (supported in versions 2012-08-10)
  82. * @method \Aws\Result exportTableToPointInTime(array $args = []) (supported in versions 2012-08-10)
  83. * @method \GuzzleHttp\Promise\Promise exportTableToPointInTimeAsync(array $args = []) (supported in versions 2012-08-10)
  84. * @method \Aws\Result getResourcePolicy(array $args = []) (supported in versions 2012-08-10)
  85. * @method \GuzzleHttp\Promise\Promise getResourcePolicyAsync(array $args = []) (supported in versions 2012-08-10)
  86. * @method \Aws\Result importTable(array $args = []) (supported in versions 2012-08-10)
  87. * @method \GuzzleHttp\Promise\Promise importTableAsync(array $args = []) (supported in versions 2012-08-10)
  88. * @method \Aws\Result listBackups(array $args = []) (supported in versions 2012-08-10)
  89. * @method \GuzzleHttp\Promise\Promise listBackupsAsync(array $args = []) (supported in versions 2012-08-10)
  90. * @method \Aws\Result listContributorInsights(array $args = []) (supported in versions 2012-08-10)
  91. * @method \GuzzleHttp\Promise\Promise listContributorInsightsAsync(array $args = []) (supported in versions 2012-08-10)
  92. * @method \Aws\Result listExports(array $args = []) (supported in versions 2012-08-10)
  93. * @method \GuzzleHttp\Promise\Promise listExportsAsync(array $args = []) (supported in versions 2012-08-10)
  94. * @method \Aws\Result listGlobalTables(array $args = []) (supported in versions 2012-08-10)
  95. * @method \GuzzleHttp\Promise\Promise listGlobalTablesAsync(array $args = []) (supported in versions 2012-08-10)
  96. * @method \Aws\Result listImports(array $args = []) (supported in versions 2012-08-10)
  97. * @method \GuzzleHttp\Promise\Promise listImportsAsync(array $args = []) (supported in versions 2012-08-10)
  98. * @method \Aws\Result listTagsOfResource(array $args = []) (supported in versions 2012-08-10)
  99. * @method \GuzzleHttp\Promise\Promise listTagsOfResourceAsync(array $args = []) (supported in versions 2012-08-10)
  100. * @method \Aws\Result putResourcePolicy(array $args = []) (supported in versions 2012-08-10)
  101. * @method \GuzzleHttp\Promise\Promise putResourcePolicyAsync(array $args = []) (supported in versions 2012-08-10)
  102. * @method \Aws\Result restoreTableFromBackup(array $args = []) (supported in versions 2012-08-10)
  103. * @method \GuzzleHttp\Promise\Promise restoreTableFromBackupAsync(array $args = []) (supported in versions 2012-08-10)
  104. * @method \Aws\Result restoreTableToPointInTime(array $args = []) (supported in versions 2012-08-10)
  105. * @method \GuzzleHttp\Promise\Promise restoreTableToPointInTimeAsync(array $args = []) (supported in versions 2012-08-10)
  106. * @method \Aws\Result tagResource(array $args = []) (supported in versions 2012-08-10)
  107. * @method \GuzzleHttp\Promise\Promise tagResourceAsync(array $args = []) (supported in versions 2012-08-10)
  108. * @method \Aws\Result transactGetItems(array $args = []) (supported in versions 2012-08-10)
  109. * @method \GuzzleHttp\Promise\Promise transactGetItemsAsync(array $args = []) (supported in versions 2012-08-10)
  110. * @method \Aws\Result transactWriteItems(array $args = []) (supported in versions 2012-08-10)
  111. * @method \GuzzleHttp\Promise\Promise transactWriteItemsAsync(array $args = []) (supported in versions 2012-08-10)
  112. * @method \Aws\Result untagResource(array $args = []) (supported in versions 2012-08-10)
  113. * @method \GuzzleHttp\Promise\Promise untagResourceAsync(array $args = []) (supported in versions 2012-08-10)
  114. * @method \Aws\Result updateContinuousBackups(array $args = []) (supported in versions 2012-08-10)
  115. * @method \GuzzleHttp\Promise\Promise updateContinuousBackupsAsync(array $args = []) (supported in versions 2012-08-10)
  116. * @method \Aws\Result updateContributorInsights(array $args = []) (supported in versions 2012-08-10)
  117. * @method \GuzzleHttp\Promise\Promise updateContributorInsightsAsync(array $args = []) (supported in versions 2012-08-10)
  118. * @method \Aws\Result updateGlobalTable(array $args = []) (supported in versions 2012-08-10)
  119. * @method \GuzzleHttp\Promise\Promise updateGlobalTableAsync(array $args = []) (supported in versions 2012-08-10)
  120. * @method \Aws\Result updateGlobalTableSettings(array $args = []) (supported in versions 2012-08-10)
  121. * @method \GuzzleHttp\Promise\Promise updateGlobalTableSettingsAsync(array $args = []) (supported in versions 2012-08-10)
  122. * @method \Aws\Result updateKinesisStreamingDestination(array $args = []) (supported in versions 2012-08-10)
  123. * @method \GuzzleHttp\Promise\Promise updateKinesisStreamingDestinationAsync(array $args = []) (supported in versions 2012-08-10)
  124. * @method \Aws\Result updateTableReplicaAutoScaling(array $args = []) (supported in versions 2012-08-10)
  125. * @method \GuzzleHttp\Promise\Promise updateTableReplicaAutoScalingAsync(array $args = []) (supported in versions 2012-08-10)
  126. * @method \Aws\Result updateTimeToLive(array $args = []) (supported in versions 2012-08-10)
  127. * @method \GuzzleHttp\Promise\Promise updateTimeToLiveAsync(array $args = []) (supported in versions 2012-08-10)
  128. */
  129. class DynamoDbClient extends AwsClient
  130. {
  131. public static function getArguments()
  132. {
  133. $args = parent::getArguments();
  134. $args['retries']['default'] = 10;
  135. $args['retries']['fn'] = [__CLASS__, '_applyRetryConfig'];
  136. $args['api_provider']['fn'] = [__CLASS__, '_applyApiProvider'];
  137. return $args;
  138. }
  139. /**
  140. * Convenience method for instantiating and registering the DynamoDB
  141. * Session handler with this DynamoDB client object.
  142. *
  143. * @param array $config Array of options for the session handler factory
  144. *
  145. * @return SessionHandler
  146. */
  147. public function registerSessionHandler(array $config = [])
  148. {
  149. $handler = SessionHandler::fromClient($this, $config);
  150. $handler->register();
  151. return $handler;
  152. }
  153. /** @internal */
  154. public static function _applyRetryConfig($value, array &$args, HandlerList $list)
  155. {
  156. if ($value) {
  157. $config = \Aws\Retry\ConfigurationProvider::unwrap($value);
  158. if ($config->getMode() === 'legacy') {
  159. $list->appendSign(
  160. Middleware::retry(
  161. RetryMiddleware::createDefaultDecider(
  162. $config->getMaxAttempts() - 1,
  163. ['error_codes' => ['TransactionInProgressException']]
  164. ),
  165. function ($retries) {
  166. return $retries
  167. ? RetryMiddleware::exponentialDelay($retries) / 2
  168. : 0;
  169. },
  170. isset($args['stats']['retries'])
  171. ? (bool)$args['stats']['retries']
  172. : false
  173. ),
  174. 'retry'
  175. );
  176. } else {
  177. $list->appendSign(
  178. RetryMiddlewareV2::wrap(
  179. $config,
  180. [
  181. 'collect_stats' => $args['stats']['retries'],
  182. 'transient_error_codes' => ['TransactionInProgressException']
  183. ]
  184. ),
  185. 'retry'
  186. );
  187. }
  188. }
  189. }
  190. /** @internal */
  191. public static function _applyApiProvider($value, array &$args, HandlerList $list)
  192. {
  193. ClientResolver::_apply_api_provider($value, $args);
  194. $args['parser'] = new Crc32ValidatingParser($args['parser']);
  195. }
  196. }