Skip to content

Instantly share code, notes, and snippets.

@bblincoe
Last active April 28, 2022 14:16
Show Gist options
  • Save bblincoe/fdf486e4edcfd994e17fc2febd548b47 to your computer and use it in GitHub Desktop.
Save bblincoe/fdf486e4edcfd994e17fc2febd548b47 to your computer and use it in GitHub Desktop.
Amazon AWS Client Throttle in Python (boto3)
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