Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iam_role_info jittered backoff #748

Merged
merged 4 commits into from
Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/748-iam_role_info-jittered-backoff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- iam_role_info - switch to jittered backoff to reduce rate limiting failures (https://github.com/ansible-collections/community.aws/pull/748).
14 changes: 6 additions & 8 deletions plugins/modules/iam_role_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,23 @@
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict


@AWSRetry.exponential_backoff()
@AWSRetry.jittered_backoff()
def list_iam_roles_with_backoff(client, **kwargs):
paginator = client.get_paginator('list_roles')
return paginator.paginate(**kwargs).build_full_result()


@AWSRetry.exponential_backoff()
@AWSRetry.jittered_backoff()
def list_iam_role_policies_with_backoff(client, role_name):
paginator = client.get_paginator('list_role_policies')
return paginator.paginate(RoleName=role_name).build_full_result()['PolicyNames']


@AWSRetry.exponential_backoff()
@AWSRetry.jittered_backoff()
tremble marked this conversation as resolved.
Show resolved Hide resolved
def list_iam_attached_role_policies_with_backoff(client, role_name):
paginator = client.get_paginator('list_attached_role_policies')
return paginator.paginate(RoleName=role_name).build_full_result()['AttachedPolicies']


@AWSRetry.exponential_backoff()
@AWSRetry.jittered_backoff()
tremble marked this conversation as resolved.
Show resolved Hide resolved
def list_iam_instance_profiles_for_role_with_backoff(client, role_name):
paginator = client.get_paginator('list_instance_profiles_for_role')
return paginator.paginate(RoleName=role_name).build_full_result()['InstanceProfiles']
Expand Down Expand Up @@ -210,7 +208,7 @@ def describe_iam_roles(module, client):
path_prefix = module.params['path_prefix']
if name:
try:
roles = [client.get_role(RoleName=name)['Role']]
roles = [client.get_role(RoleName=name, aws_retry=True)['Role']]
except is_boto3_error_code('NoSuchEntity'):
return []
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except
Expand Down Expand Up @@ -245,7 +243,7 @@ def main():
if module._name == 'iam_role_facts':
module.deprecate("The 'iam_role_facts' module has been renamed to 'iam_role_info'", date='2021-12-01', collection_name='community.aws')

client = module.client('iam')
client = module.client('iam', retry_decorator=AWSRetry.jittered_backoff())

module.exit_json(changed=False, iam_roles=describe_iam_roles(module, client))

Expand Down