Skip to content

Commit

Permalink
Update ec2_vpc_endpoint_info AWS retries
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble committed Apr 10, 2021
1 parent 8b9ee85 commit 8acde77
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/537-ec2_vpc_endpoint_info-retries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- ec2_vpc_endpoint_info - use boto3 paginator when fetching services (https://github.com/ansible-collections/community.aws/pull/537).
- ec2_vpc_endpoint_info - ensure paginated endpoint description is retried on common AWS failures (https://github.com/ansible-collections/community.aws/pull/537).
34 changes: 20 additions & 14 deletions plugins/modules/ec2_vpc_endpoint_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,36 +126,42 @@
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list


@AWSRetry.exponential_backoff()
@AWSRetry.jittered_backoff()
def _describe_endpoints(client, **params):
paginator = client.get_paginator('describe_vpc_endpoints')
return paginator.paginate(**params).build_full_result()


@AWSRetry.jittered_backoff()
def _describe_endpoint_services(client, **params):
paginator = client.get_paginator('describe_vpc_endpoint_services')
return paginator.paginate(**params).build_full_result()


def get_supported_services(client, module):
results = list()
params = dict()
while True:
response = client.describe_vpc_endpoint_services(**params)
results.extend(response['ServiceNames'])
if 'NextToken' in response:
params['NextToken'] = response['NextToken']
else:
break
try:
services = _describe_endpoint_services(client)
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
module.fail_json_aws(e, msg="Failed to get endpoint servicess")

results = list(services['ServiceNames'])
return dict(service_names=results)


@AWSRetry.exponential_backoff()
def get_endpoints(client, module):
results = list()
params = dict()
params['Filters'] = ansible_dict_to_boto3_filter_list(module.params.get('filters'))
if module.params.get('vpc_endpoint_ids'):
params['VpcEndpointIds'] = module.params.get('vpc_endpoint_ids')
try:
paginator = client.get_paginator('describe_vpc_endpoints')
results = paginator.paginate(**params).build_full_result()['VpcEndpoints']

results = _describe_endpoints(client, **params)['VpcEndpoints']
results = normalize_boto3_result(results)
except is_boto3_error_code('InvalidVpcEndpointId.NotFound'):
module.exit_json(msg='VpcEndpoint {0} does not exist'.format(module.params.get('vpc_endpoint_ids')), vpc_endpoints=[])
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, msg="Failed to get endpoints")

return dict(vpc_endpoints=[camel_dict_to_snake_dict(result) for result in results])


Expand Down

0 comments on commit 8acde77

Please sign in to comment.