Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 在AWS(boto3)呼叫中使用韧性_Python 3.x_Amazon Web Services_Error Handling_Boto3 - Fatal编程技术网

Python 3.x 在AWS(boto3)呼叫中使用韧性

Python 3.x 在AWS(boto3)呼叫中使用韧性,python-3.x,amazon-web-services,error-handling,boto3,Python 3.x,Amazon Web Services,Error Handling,Boto3,我在使用boto3调用AWS时遇到间歇性错误。在下面的示例中,由于速率限制,调用instance.all()或i.vpc.tags都可能失败: for i in instance.all(): tags = i.vpc.tags 通常情况下,我在自己的函数中使用Tensity作为装饰器,但显然这不能通过调用完成,因为它来自导入的库。如果它不在for循环中,我可以使用重试功能,如下所示: r = tenacity.Retrying( reraise=True, wa

我在使用boto3调用AWS时遇到间歇性错误。在下面的示例中,由于速率限制,调用instance.all()或i.vpc.tags都可能失败:

 for i in instance.all():
     tags = i.vpc.tags
通常情况下,我在自己的函数中使用Tensity作为装饰器,但显然这不能通过调用完成,因为它来自导入的库。如果它不在for循环中,我可以使用重试功能,如下所示:

r = tenacity.Retrying(
    reraise=True, 
    wait=tenacity.wait_random_exponential(multiplier=1, max=60), 
    stop=tenacity.stop_after_delay(130))

r.call(call_wrapped_in_tenacity())
from botocore.config import Config
config = Config(retries=dict(max_attempts=20))
ec2_client = boto3.client('ec2', config=config)

那么,有没有一种方法可以在不为每个AWS构建新函数的情况下包装这两个对AWS的调用,同时保持重试功能?

如果创建自己的函数超出了范围,那么这是我找到的解决此问题的唯一方法。基本上,当您创建boto3客户端时,您会在boto配置中向其传递一个对您自己设置的引用,如下所示:

r = tenacity.Retrying(
    reraise=True, 
    wait=tenacity.wait_random_exponential(multiplier=1, max=60), 
    stop=tenacity.stop_after_delay(130))

r.call(call_wrapped_in_tenacity())
from botocore.config import Config
config = Config(retries=dict(max_attempts=20))
ec2_client = boto3.client('ec2', config=config)