Skip to content

Commit

Permalink
ec2_vpc_nat_gateway_info: add retry decorator (ansible-collections#446)
Browse files Browse the repository at this point in the history
* Solve RequestLimitExceeded error by adding the retry decorator

Signed-off-by: Alina Buzachis <[email protected]>

Co-authored-by: Alina Buzachis <[email protected]>

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@52fb230
  • Loading branch information
2 people authored and jillr committed Aug 27, 2021
1 parent 1d374bc commit 1e61cf6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions plugins/modules/ec2_vpc_nat_gateway_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))

Expand Down Expand Up @@ -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')

Expand Down

0 comments on commit 1e61cf6

Please sign in to comment.