Skip to content

Commit

Permalink
Add backoff logic to elb_application_lb_info (#977) (#995)
Browse files Browse the repository at this point in the history
[PR #977/280d7a2f backport][stable-2] Add backoff logic to elb_application_lb_info

This is a backport of PR #977 as merged into main (280d7a2).
SUMMARY
From time to time rate limiting failures occur on the usage of this module, this PR adds backoff logic to the module to improve its stability.
fatal: [127.0.0.1 -> 127.0.0.1]: FAILED! => changed=false 
boto3_version: 1.20.34
botocore_version: 1.23.34
error:
code: Throttling
message: Rate exceeded
type: Sender
msg: 'Failed to list load balancers: An error occurred (Throttling) when calling the DescribeLoadBalancers operation (reached max retries: 4): Rate exceeded'
response_metadata:
http_headers:
content-length: '271'
content-type: text/xml
date: Thu, 10 Mar 2022 10:34:23 GMT
x-amzn-requestid: xxxxx
http_status_code: 400
max_attempts_reached: true
request_id: xxxxx
retry_attempts: 4

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
elb_application_lb_info
ADDITIONAL INFORMATION
  • Loading branch information
patchback[bot] authored Mar 15, 2022
1 parent ffbf199 commit 869b956
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/977-add-backoff-logic-elb-info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- Add backoff retry logic to elb_application_lb_info (https://github.com/ansible-collections/community.aws/pull/977)
17 changes: 11 additions & 6 deletions plugins/modules/elb_application_lb_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,13 @@

from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry, boto3_tag_list_to_ansible_dict


@AWSRetry.jittered_backoff()
def get_paginator(connection, **kwargs):
paginator = connection.get_paginator('describe_load_balancers')
return paginator.paginate(**kwargs).build_full_result()


def get_elb_listeners(connection, module, elb_arn):
Expand Down Expand Up @@ -206,13 +212,12 @@ def list_load_balancers(connection, module):
names = module.params.get("names")

try:
load_balancer_paginator = connection.get_paginator('describe_load_balancers')
if not load_balancer_arns and not names:
load_balancers = load_balancer_paginator.paginate().build_full_result()
load_balancers = get_paginator(connection)
if load_balancer_arns:
load_balancers = load_balancer_paginator.paginate(LoadBalancerArns=load_balancer_arns).build_full_result()
load_balancers = get_paginator(connection, LoadBalancerArns=load_balancer_arns)
if names:
load_balancers = load_balancer_paginator.paginate(Names=names).build_full_result()
load_balancers = get_paginator(connection, Names=names)
except is_boto3_error_code('LoadBalancerNotFound'):
module.exit_json(load_balancers=[])
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except
Expand Down Expand Up @@ -259,7 +264,7 @@ def main():
date='2021-12-01', collection_name='community.aws')

try:
connection = module.client('elbv2')
connection = module.client('elbv2', retry_decorator=AWSRetry.jittered_backoff(retries=10))
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 869b956

Please sign in to comment.