Skip to content

Commit

Permalink
Awsretry/cloudfront distribution (ansible-collections#297)
Browse files Browse the repository at this point in the history
Awsretry/cloudfront distribution

SUMMARY
Adding AWSRetry.exponential_backoff when updating a cloudfront distribution.
Fixes ansible-collections#296
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
cloudfront_distribution

Reviewed-by: matej <strahek@gmail.com>
Reviewed-by: Mark Chappell <None>
Reviewed-by: Francesc Navarro <fnavarro@debelop.com>
Reviewed-by: Alina Buzachis <None>
Reviewed-by: Markus Bergholz <git@osuv.de>
  • Loading branch information
Francesc Navarro authored and abikouo committed Sep 18, 2023
1 parent 8e0f2fa commit 3fd4318
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions cloudfront_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@
from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.cloudfront_facts import CloudFrontFactsServiceManager
from ansible.module_utils.common.dict_transformations import recursive_diff
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import compare_aws_tags, ansible_dict_to_boto3_tag_list, boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry, compare_aws_tags, ansible_dict_to_boto3_tag_list, boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict, snake_dict_to_camel_dict
import datetime

Expand Down Expand Up @@ -1433,50 +1433,50 @@ def ansible_list_to_cloudfront_list(list_items=None, include_quantity=True):
def create_distribution(client, module, config, tags):
try:
if not tags:
return client.create_distribution(DistributionConfig=config)['Distribution']
return client.create_distribution(aws_retry=True, DistributionConfig=config)['Distribution']
else:
distribution_config_with_tags = {
'DistributionConfig': config,
'Tags': {
'Items': tags
}
}
return client.create_distribution_with_tags(DistributionConfigWithTags=distribution_config_with_tags)['Distribution']
return client.create_distribution_with_tags(aws_retry=True, DistributionConfigWithTags=distribution_config_with_tags)['Distribution']
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Error creating distribution")


def delete_distribution(client, module, distribution):
try:
return client.delete_distribution(Id=distribution['Distribution']['Id'], IfMatch=distribution['ETag'])
return client.delete_distribution(aws_retry=True, Id=distribution['Distribution']['Id'], IfMatch=distribution['ETag'])
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Error deleting distribution %s" % to_native(distribution['Distribution']))


def update_distribution(client, module, config, distribution_id, e_tag):
try:
return client.update_distribution(DistributionConfig=config, Id=distribution_id, IfMatch=e_tag)['Distribution']
return client.update_distribution(aws_retry=True, DistributionConfig=config, Id=distribution_id, IfMatch=e_tag)['Distribution']
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Error updating distribution to %s" % to_native(config))


def tag_resource(client, module, arn, tags):
try:
return client.tag_resource(Resource=arn, Tags=dict(Items=tags))
return client.tag_resource(aws_retry=True, Resource=arn, Tags=dict(Items=tags))
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Error tagging resource")


def untag_resource(client, module, arn, tag_keys):
try:
return client.untag_resource(Resource=arn, TagKeys=dict(Items=tag_keys))
return client.untag_resource(aws_retry=True, Resource=arn, TagKeys=dict(Items=tag_keys))
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Error untagging resource")


def list_tags_for_resource(client, module, arn):
try:
response = client.list_tags_for_resource(Resource=arn)
response = client.list_tags_for_resource(aws_retry=True, Resource=arn)
return boto3_tag_list_to_ansible_dict(response.get('Tags').get('Items'))
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Error listing tags for resource")
Expand Down Expand Up @@ -2152,7 +2152,7 @@ def main():
]
)

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

validation_mgr = CloudFrontValidationManager(module)

Expand Down

0 comments on commit 3fd4318

Please sign in to comment.