From 0e23ba1cef265b1cf9699548ef6e639b9392af8b Mon Sep 17 00:00:00 2001 From: Alina Buzachis <49211501+alinabuzachis@users.noreply.github.com> Date: Thu, 25 Feb 2021 21:11:13 +0100 Subject: [PATCH] ec2_vpc_nat_gateway_info: add retry decorator (#446) * Solve RequestLimitExceeded error by adding the retry decorator Signed-off-by: Alina Buzachis Co-authored-by: Alina Buzachis This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/52fb23054101acbd78e13a45048ddcf935899586 --- plugins/modules/ec2_vpc_nat_gateway_info.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/modules/ec2_vpc_nat_gateway_info.py b/plugins/modules/ec2_vpc_nat_gateway_info.py index 97816c72362..7d31eeac993 100644 --- a/plugins/modules/ec2_vpc_nat_gateway_info.py +++ b/plugins/modules/ec2_vpc_nat_gateway_info.py @@ -84,6 +84,7 @@ pass # Handled by AnsibleAWSModule from ansible.module_utils._text import to_native +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list @@ -102,7 +103,7 @@ def get_nat_gateways(client, module, nat_gateway_id=None): params['NatGatewayIds'] = module.params.get('nat_gateway_ids') try: - result = json.loads(json.dumps(client.describe_nat_gateways(**params), default=date_handler)) + result = json.loads(json.dumps(client.describe_nat_gateways(aws_retry=True, **params), default=date_handler)) except Exception as e: module.fail_json(msg=to_native(e)) @@ -131,7 +132,7 @@ def main(): date='2021-12-01', collection_name='community.aws') try: - connection = module.client('ec2') + connection = module.client('ec2', retry_decorator=AWSRetry.jittered_backoff()) except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: module.fail_json_aws(e, msg='Failed to connect to AWS')