setConfig($config) ->setConfigDefaults(array( // DynamoDB does not use redirects self::DISABLE_REDIRECTS => true, Options::VERSION => self::LATEST_API_VERSION, Options::SERVICE_DESCRIPTION => __DIR__ . '/Resources/dynamodb-%s.php', // DynamoDB does not require response processing other than turning JSON into an array self::COMMAND_PARAMS => array(Cmd::RESPONSE_PROCESSING => Cmd::TYPE_NO_TRANSLATION) )) ->setExceptionParser($exceptionParser) ->build(); } /** * Create a DynamoDB-specific backoff strategy. * * @param JsonQueryExceptionParser $exceptionParser * * @return TruncatedBackoffStrategy * @internal */ public static function createDynamoDbBackoffStrategy(JsonQueryExceptionParser $exceptionParser, $retries = 11) { // Retry failed requests up to 11 times instead of the normal 3 return new TruncatedBackoffStrategy($retries, // Retry failed requests with 400-level responses due to throttling new ThrottlingErrorChecker($exceptionParser, // Retry failed requests with 500-level responses new HttpBackoffStrategy(null, // Retry failed requests due to transient network or cURL problems new CurlBackoffStrategy(null, new ExpiredCredentialsChecker($exceptionParser, // Use the custom retry delay method instead of default exponential backoff new CallbackBackoffStrategy(__CLASS__ . '::calculateRetryDelay', false) ) ) ) ) ); } /** * Formats a value as a DynamoDB attribute. * * @param mixed $value The value to format for DynamoDB. * @param string $format The type of format (e.g. put, update). * * @return array The formatted value. * @deprecated The new DynamoDB document model, including the new types * (L, M, BOOL, NULL), is not supported by this method. */ public function formatValue($value, $format = Attribute::FORMAT_PUT) { return Attribute::factory($value)->getFormatted($format); } /** * Formats an array of values as DynamoDB attributes. * * @param array $values The values to format for DynamoDB. * @param string $format The type of format (e.g. put, update). * * @return array The formatted values. * @deprecated The new DynamoDB document model, including the new types * (L, M, BOOL, NULL), is not supported by this method. */ public function formatAttributes(array $values, $format = Attribute::FORMAT_PUT) { $formatted = array(); foreach ($values as $key => $value) { $formatted[$key] = $this->formatValue($value, $format); } return $formatted; } /** * Calculate the amount of time needed for an exponential backoff to wait * before retrying a request * * @param int $retries Number of retries * * @return float Returns the amount of time to wait in seconds * @internal */ public static function calculateRetryDelay($retries) { return $retries == 0 ? 0 : (50 * (int) pow(2, $retries - 1)) / 1000; } /** * Convenience method for instantiating and registering the DynamoDB * Session handler with this DynamoDB client object. * * @param array $config Array of options for the session handler factory * * @return SessionHandler */ public function registerSessionHandler(array $config = array()) { $config = array_replace(array('dynamodb_client' => $this), $config); $handler = SessionHandler::factory($config); $handler->register(); return $handler; } }