|
4 | 4 | import logging
|
5 | 5 | import uuid
|
6 | 6 | from threading import local
|
7 |
| -from typing import Any, Dict, List, Mapping, Optional, Sequence, cast |
| 7 | +from typing import Any, Dict, List, Mapping, Optional, Sequence, cast, Literal |
8 | 8 |
|
9 | 9 | import botocore.client
|
10 | 10 | import botocore.exceptions
|
@@ -247,6 +247,7 @@ def __init__(self,
|
247 | 247 | read_timeout_seconds: Optional[float] = None,
|
248 | 248 | connect_timeout_seconds: Optional[float] = None,
|
249 | 249 | max_retry_attempts: Optional[int] = None,
|
| 250 | + retry_configuration: Optional[Literal["LEGACY"] | dict] = None, |
250 | 251 | max_pool_connections: Optional[int] = None,
|
251 | 252 | extra_headers: Optional[Mapping[str, str]] = None,
|
252 | 253 | aws_access_key_id: Optional[str] = None,
|
@@ -277,6 +278,11 @@ def __init__(self,
|
277 | 278 | else:
|
278 | 279 | self._max_retry_attempts_exception = get_settings_value('max_retry_attempts')
|
279 | 280 |
|
| 281 | + if retry_configuration is not None: |
| 282 | + self._retry_configuration = retry_configuration |
| 283 | + else: |
| 284 | + self._retry_configuration = get_settings_value('retry_configuration') |
| 285 | + |
280 | 286 | if max_pool_connections is not None:
|
281 | 287 | self._max_pool_connections = max_pool_connections
|
282 | 288 | else:
|
@@ -399,15 +405,22 @@ def client(self) -> BotocoreBaseClientPrivate:
|
399 | 405 | # if the client does not have credentials, we create a new client
|
400 | 406 | # otherwise the client is permanently poisoned in the case of metadata service flakiness when using IAM roles
|
401 | 407 | if not self._client or (self._client._request_signer and not self._client._request_signer._credentials):
|
| 408 | + # Check if we are using the "LEGACY" retry mode to keep previous PynamoDB |
| 409 | + # retry behavior, or if we are using the new retry configuration settings. |
| 410 | + if self._retry_configuration != "LEGACY": |
| 411 | + retries = self._retry_configuration |
| 412 | + else: |
| 413 | + retries = { |
| 414 | + 'total_max_attempts': 1 + self._max_retry_attempts_exception, |
| 415 | + 'mode': 'standard', |
| 416 | + } |
| 417 | + |
402 | 418 | config = botocore.client.Config(
|
403 | 419 | parameter_validation=False, # Disable unnecessary validation for performance
|
404 | 420 | connect_timeout=self._connect_timeout_seconds,
|
405 | 421 | read_timeout=self._read_timeout_seconds,
|
406 | 422 | max_pool_connections=self._max_pool_connections,
|
407 |
| - retries={ |
408 |
| - 'total_max_attempts': 1 + self._max_retry_attempts_exception, |
409 |
| - 'mode': 'standard', |
410 |
| - } |
| 423 | + retries=retries |
411 | 424 | )
|
412 | 425 | self._client = cast(BotocoreBaseClientPrivate, self.session.create_client(SERVICE_NAME, self.region, endpoint_url=self.host, config=config))
|
413 | 426 |
|
|
0 commit comments