import boto3 import botocore from random import randint from time import sleep def client_throttle(action, **kwargs): while True: try: return action(**kwargs) except botocore.exceptions.ClientError as e: # Naive way of throttling timeout = randint(1, 5) print '[Warning] API rate exceeded, throttling back for %d seconds' % timeout sleep(timeout)