36

In boto3 or botocore, how do I do the equivalent of setting the number of request retries?

e.g. in boto2

from boto import config
config.set('Boto', 'num_retries', '20')

How do I do this in boto3? I've tried

conn._session.set_config_variable("num_retries", "20")

but when I then get_config_variable("num_retries"), None is returned.

Daniel777
  • 851
  • 8
  • 20
DG812
  • 460
  • 1
  • 5
  • 5

1 Answers1

55

You should now be able to do this, at least for ec2 and perhaps other clients as well:

from botocore.config import Config

config = Config(
    retries = dict(
        max_attempts = 10
    )
)

ec2 = boto3.client('ec2', config=config)
Marty
  • 2,104
  • 2
  • 23
  • 42
  • 7
    Just adding API URL in case if anyone wants to try other parameters too. The answer works! https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html – Jugal Panchal Apr 02 '20 at 16:19
  • 1
    And some SDK documentation now as well: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/retries.html – selle Sep 14 '20 at 13:39
  • how can we do this for paginators? – Bored Monkey Jan 05 '23 at 21:43