Skip to content

Commit

Permalink
Merge pull request #88 from stolendog/add-boto3-retries-config
Browse files Browse the repository at this point in the history
Increase boto3 max_attempts to 10
  • Loading branch information
bonclay7 committed Aug 17, 2018
2 parents c5cfe7f + 9d8e5f9 commit cebe632
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions amicleaner/core.py
Expand Up @@ -6,7 +6,11 @@
from builtins import object
import boto3
from botocore.exceptions import ClientError
from botocore.config import Config

from .resources.config import BOTO3_RETRIES
from .resources.models import AMI

from datetime import datetime


Expand All @@ -15,7 +19,7 @@ class OrphanSnapshotCleaner(object):
""" Finds and removes ebs snapshots left orphaned """

def __init__(self, ec2=None):
self.ec2 = ec2 or boto3.client('ec2')
self.ec2 = ec2 or boto3.client('ec2', config=Config(retries={'max_attempts': BOTO3_RETRIES}))

def get_snapshots_filter(self):

Expand Down Expand Up @@ -92,7 +96,7 @@ def log(self, msg):
class AMICleaner(object):

def __init__(self, ec2=None):
self.ec2 = ec2 or boto3.client('ec2')
self.ec2 = ec2 or boto3.client('ec2', config=Config(retries={'max_attempts': BOTO3_RETRIES}))

@staticmethod
def get_ami_sorting_key(ami):
Expand Down
4 changes: 3 additions & 1 deletion amicleaner/fetch.py
Expand Up @@ -4,6 +4,8 @@
from __future__ import absolute_import
from builtins import object
import boto3
from botocore.config import Config
from .resources.config import BOTO3_RETRIES
from .resources.models import AMI


Expand All @@ -15,7 +17,7 @@ def __init__(self, ec2=None, autoscaling=None):

""" Initializes aws sdk clients """

self.ec2 = ec2 or boto3.client('ec2')
self.ec2 = ec2 or boto3.client('ec2', config=Config(retries={'max_attempts': BOTO3_RETRIES}))
self.asg = autoscaling or boto3.client('autoscaling')

def fetch_available_amis(self):
Expand Down
2 changes: 2 additions & 0 deletions amicleaner/resources/config.py
Expand Up @@ -32,3 +32,5 @@
# Number of days amis to keep based on creation date and grouping strategy
# not including the ami currently running by an ec2 instance
AMI_MIN_DAYS = -1

BOTO3_RETRIES = 10

0 comments on commit cebe632

Please sign in to comment.