-
-
Save kwoods/317bc719049eef2de7d43c2ec2357033 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