How do botocore retry modes work, and how do you configure them?
AdvancedConceptboto3 & AWS automation
Answer
botocore retries transient errors (throttling, 5xx, connection errors) automatically.
legacy: the long-standing boto3 default if you configure nothing; 5 total attempts for most services.standard: 3 attempts by default, consistent jittered exponential backoff, broader set of retryable errors. The mode AWS recommends.adaptive: standard plus client-side rate limiting that slows down when throttled; good for bulk scanners.
from botocore.config import Config
cfg = Config(retries={"max_attempts": 10, "mode": "adaptive"},
connect_timeout=5, read_timeout=30, max_pool_connections=50)
ec2 = boto3.client("ec2", config=cfg)
Can also be set via AWS_RETRY_MODE and AWS_MAX_ATTEMPTS.
More on boto3 & AWS automation
What is the difference between a boto3 Session, client and resource?BeginnerHow does boto3 find credentials?BeginnerHow does boto3 decide the region, and what is the gotcha with `AWS_REGION`?AdvancedWhy do you need paginators, and how do you use them?BeginnerWhat is JMESPath `search()` on paginators?AdvancedHow do you handle errors from boto3?Beginner