Skip to content

implement request ratelimiting #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ Usage
The name of the role that backup-monkey will assume
when doing a cross-account snapshot. E.g. --cross-
account-role Snapshot
--ratelimit RATELIMIT
Time to wait in seconds between subsequent requests to
the AWS API. E.g. --ratelimit 5

Examples
--------
Expand Down
5 changes: 4 additions & 1 deletion backup_monkey/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def run():
help='Do a cross-account snapshot (this is the account number to do snapshots on). NOTE: This requires that you pass in the --cross-account-role parameter. E.g. --cross-account-number 111111111111 --cross-account-role Snapshot')
parser.add_argument('--cross-account-role', action='store',
help='The name of the role that backup-monkey will assume when doing a cross-account snapshot. E.g. --cross-account-role Snapshot')
parser.add_argument('--ratelimit', action='store', default=0,
help='Time to wait in seconds between subsequent requests to the AWS API. E.g. --ratelimit 5')

args = parser.parse_args()

Expand Down Expand Up @@ -95,7 +97,8 @@ def run():
args.reverse_tags,
args.label,
args.cross_account_number,
args.cross_account_role)
args.cross_account_role,
args.ratelimit)

if not args.remove_only:
monkey.snapshot_volumes()
Expand Down
5 changes: 4 additions & 1 deletion backup_monkey/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from time import sleep

from boto.exception import NoAuthHandlerFound
from boto import ec2
Expand All @@ -22,7 +23,7 @@
log = logging.getLogger(__name__)

class BackupMonkey(object):
def __init__(self, region, max_snapshots_per_volume, tags, reverse_tags, label, cross_account_number, cross_account_role):
def __init__(self, region, max_snapshots_per_volume, tags, reverse_tags, label, cross_account_number, cross_account_role, ratelimit):
self._region = region
self._prefix = 'BACKUP_MONKEY'
if label:
Expand All @@ -32,6 +33,7 @@ def __init__(self, region, max_snapshots_per_volume, tags, reverse_tags, label,
self._reverse_tags = reverse_tags
self._cross_account_number = cross_account_number
self._cross_account_role = cross_account_role
self._ratelimit = ratelimit
self._conn = self.get_connection()

def get_connection(self):
Expand Down Expand Up @@ -116,6 +118,7 @@ def snapshot_volumes(self):
description = ' '.join(description_parts)
log.info('Creating snapshot of %s: %s', volume.id, description)
volume.create_snapshot(description)
sleep(self._ratelimit)
return True


Expand Down