Last active
April 28, 2022 14:16
-
-
Save bblincoe/fdf486e4edcfd994e17fc2febd548b47 to your computer and use it in GitHub Desktop.
Amazon AWS Client Throttle in Python (boto3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment