From 9d8e5f9fe4c8aa89e172f5d6aa25b5c7056ca666 Mon Sep 17 00:00:00 2001 From: Jonas Mardosas Date: Sun, 29 Jul 2018 19:28:26 +0300 Subject: [PATCH] Increase boto3 max_attempts to 10 to have ability to use exponential backoff --- amicleaner/core.py | 8 ++++++-- amicleaner/fetch.py | 4 +++- amicleaner/resources/config.py | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/amicleaner/core.py b/amicleaner/core.py index 7949d3c..f4b18ae 100644 --- a/amicleaner/core.py +++ b/amicleaner/core.py @@ -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 @@ -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): @@ -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): diff --git a/amicleaner/fetch.py b/amicleaner/fetch.py index 68dff74..015a3bb 100644 --- a/amicleaner/fetch.py +++ b/amicleaner/fetch.py @@ -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 @@ -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): diff --git a/amicleaner/resources/config.py b/amicleaner/resources/config.py index 72da975..30391bc 100644 --- a/amicleaner/resources/config.py +++ b/amicleaner/resources/config.py @@ -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