Retries - Boto3 1.34.74 documentation

Boto3 includes a variety of both retry configurations as well as configuration methods to consider when creating your client object. This first way to define your retry configuration is to update your global AWS configuration file. The default location for your AWS config file is ~/.aws/config. Heres an example of an AWS config file with

Boto3 includes a variety of both retry configurations as well as configuration methods to consider when creating your client object.

Defining a retry configuration in your AWS configuration file#

This first way to define your retry configuration is to update your global AWS configuration file. The default location for your AWS config file is ~/.aws/config. Here’s an example of an AWS config file with the retry configuration options used:

[myConfigProfile] region = us-east-1 max_attempts = 10 retry_mode = standard 

Any Boto3 script or code that uses your AWS config file inherits these configurations when using your profile, unless otherwise explicitly overwritten by a Config object when instantiating your client object at runtime. If no configuration options are set, the default retry mode value is legacy, and the default max_attempts value is 5.

Defining a retry configuration in a Config object for your Boto3 client#

The second way to define your retry configuration is to use botocore to enable more flexibility for you to specify your retry configuration using a Config object that you can pass to your client at runtime. This method is useful if you don’t want to configure retry behavior globally with your AWS config file

Additionally, if your AWS configuration file is configured with retry behavior, but you want to override those global settings, you can use the Config object to override an individual client object at runtime.

As shown in the following example, the Config object takes a retries dictionary where you can supply your two configuration options, max_attempts and mode, and the values for each.

config = Config( retries = { 'max_attempts': 10, 'mode': 'standard' } ) 

Note

The AWS configuration file uses retry_mode and the Config object uses mode. Although named differently, they both refer to the same retry configuration whose options are legacy (default), standard, and adaptive.

The following is an example of instantiating a Config object and passing it into an Amazon EC2 client to use at runtime.

import boto3 from botocore.config import Config config = Config( retries = { 'max_attempts': 10, 'mode': 'standard' } ) ec2 = boto3.client('ec2', config=config) 

Note

As mentioned previously, if no configuration options are set, the default mode is legacy and the default max_attempts is 5.

ncG1vNJzZmian6m8dHrAppizp56WxLR6wqikaK5hZLGwr9SmnKeskam2sLqOmqeiZ5yWwaa%2F02ierqGUmnyzsdOroJ6rXp3Brrg%3D

 Share!