Skip to content

Instantly share code, notes, and snippets.

@kwoods
Forked from bblincoe/client_throttle.py
Created November 8, 2016 03:17
Show Gist options
  • Save kwoods/317bc719049eef2de7d43c2ec2357033 to your computer and use it in GitHub Desktop.
Save kwoods/317bc719049eef2de7d43c2ec2357033 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