# Buggy code
def validate_cache_behavior(
    self, config, cache_behavior, valid_origins, is_default_cache=False
):
    if is_default_cache and cache_behavior is None:
        cache_behavior = {}
    if cache_behavior is None and valid_origins is not None:
        return config
    cache_behavior = self.validate_cache_behavior_first_level_keys(
        config, cache_behavior, valid_origins, is_default_cache
    )
    cache_behavior = self.validate_forwarded_values(
        config, cache_behavior.get("forwarded_values"), cache_behavior
    )
    cache_behavior = self.validate_allowed_methods(
        config, cache_behavior.get("allowed_methods"), cache_behavior
    )
    cache_behavior = self.validate_lambda_function_associations(
        config, cache_behavior.get("lambda_function_associations"), cache_behavior
    )
    cache_behavior = self.validate_trusted_signers(
        config, cache_behavior.get("trusted_signers"), cache_behavior
    )
    return cache_behavior


# Traceback (CustomError)
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: InvalidArgument: An error occurred (InvalidArgument) when calling the UpdateDistribution operation: The parameter Field level encryption id is required.
Using module file /usr/local/lib/python2.7/site-packages/ansible/modules/cloud/amazon/cloudfront_distribution.py
<127.0.0.1> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/kdelong/.ansible/tmp/ansible-tmp-1527269181.25-141910903271774 `" &amp;&amp; echo ansible-tmp-1527269181.25
-141910903271774="` echo /home/kdelong/.ansible/tmp/ansible-tmp-1527269181.25-141910903271774 `" ) &amp;&amp; sleep 0'
<127.0.0.1> PUT /home/kdelong/.ansible/tmp/ansible-local-316195O2hYZ/tmptVNofO TO /home/kdelong/.ansible/tmp/ansible-tmp-1527269181.25-141910903271774/cloudfront_dis
tribution.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/kdelong/.ansible/tmp/ansible-tmp-1527269181.25-141910903271774/ /home/kdelong/.ansible/tmp/ansible-tmp-1527269181.25-141
910903271774/cloudfront_distribution.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2.7 /home/kdelong/.ansible/tmp/ansible-tmp-1527269181.25-141910903271774/cloudfront_distribution.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/kdelong/.ansible/tmp/ansible-tmp-1527269181.25-141910903271774/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_OmI3VZ/ansible_module_cloudfront_distribution.py", line 1190, in update_distribution
return client.update_distribution(DistributionConfig=config, Id=distribution_id, IfMatch=e_tag)['Distribution']
File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 314, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 612, in _make_api_call
raise error_class(parsed_response, operation_name)
InvalidArgument: An error occurred (InvalidArgument) when calling the UpdateDistribution operation: The parameter Field level encryption id is required.

failed: [localhost] (item={u'alias': u'ourdomain.ourco.com', u'log_prefix': u'sub-web-cloudfront/prod/', u'domain_name': u'our-bucket.s3.amazonaws.com', u'
origin_id': u'S3-our-origin'}) => {
"changed": false,
"error": {
"code": "InvalidArgument",
"message": "The parameter Field level encryption id is required.",
"type": "Sender"
},
"invocation": {
"module_args": {
"alias": "ourdomain.ourco.com",
"aliases": [
"ourdomain.ourco.com"
],
"aws_access_key": null,
"aws_secret_key": null,
"cache_behaviors": null,
"caller_reference": null,
"comment": null,
"custom_error_responses": [
{
"error_caching_min_t_t_l": 300,
"error_code": 403,
"response_code": "200",
"response_page_path": "/index.html"
}
],
"default_cache_behavior": {
"allowed_methods": {
"cached_methods": {
"items": [
"HEAD",
"GET"
],
"quantity": 2
},
"items": [
"HEAD",
"GET"
],
"quantity": 2
},
"compress": false,
"default_t_t_l": 86400,
"forwarded_values": {
"cookies": {
"forward": "none"
},
"headers": {
"quantity": 0
},
"query_string": false,
"query_string_cache_keys": {
"quantity": 0
}
},
"lambda_function_associations": {
"quantity": 0
},
"max_t_t_l": 31536000,
"min_t_t_l": 0,
"smooth_streaming": false,
"target_origin_id": "S3-my-bucket",
"trusted_signers": {
"enabled": false,
"quantity": 0
},
"viewer_protocol_policy": "redirect-to-https"
},
"default_origin_domain_name": null,
"default_origin_path": null,
"default_root_object": "index.html",
"distribution_id": null,
"e_tag": null,
"ec2_url": null,
"enabled": true,
"http_version": "http2",
"ipv6_enabled": true,
"logging": {
"bucket": "our-logs.s3.amazonaws.com",
"enabled": true,
"include_cookies": false,
"prefix": "sub-web-cloudfront/prod/"
},
"origins": [
{
"custom_headers": {
"quantity": 0
},
"domain_name": "our-bucket.s3.amazonaws.com",
"id": "S3-our-origin",
"origin_path": "",
"s3_origin_config": {
"origin_access_identity": "origin-access-identity/cloudfront/XXX"
}
}
],
"price_class": "PriceClass_100",
"profile": null,
"purge_aliases": false,
"purge_cache_behaviors": false,
"purge_custom_error_responses": false,
"purge_origins": false,
"purge_tags": false,
"region": null,
"restrictions": null,
"security_token": null,
"state": "present",
"tags": {},
"validate_certs": true,
"viewer_certificate": {
"a_c_m_certificate_arn": "arn:aws:acm:us-east-1:1234567890:certificate/XXX",
"minimum_protocol_version": "TLSv1.1_2016",
"s_s_l_support_method": "sni-only"
},
"wait": false,
"wait_timeout": 1800,
"web_acl_id": null
}
},
"item": {
"alias": "ourdomain.ourco.com",
"domain_name": "our-bucket.s3.amazonaws.com",
"log_prefix": "sub-web-cloudfront/prod/",
"origin_id": "S3-our-origin"
},
"msg": "Error updating distribution to {u'Comment': '', u'Restrictions': {u'GeoRestriction': {u'RestrictionType': 'none', u'Quantity': 0}}, u'Logging': {'Enabled': True, 'Prefix': 'sub-web-cloudfront/prod/', 'Bucket': 'our-logs.s3.amazonaws.com', 'IncludeCookies': False}, u'WebACLId': '', u'Origins': {'Items': [{'OriginPath': '', 'CustomHeaders': {'Quantity': 0}, 'S3OriginConfig': {'OriginAccessIdentity': 'origin-access-identity/cloudfront/XXX'}, 'Id': 'S3-our-origin', 'DomainName': 'our-bucket.s3.amazonaws.com'}], 'Quantity': 1}, u'PriceClass': 'PriceClass_100', u'DefaultRootObject': 'index.html', u'Enabled': True, u'DefaultCacheBehavior': {'TrustedSigners': {'Enabled': False, 'Quantity': 0}, 'LambdaFunctionAssociations': {u'Quantity': 0}, 'TargetOriginId': 'S3-our-origin', 'ViewerProtocolPolicy': 'redirect-to-https', 'ForwardedValues': {'Headers': {'Quantity': 0}, 'Cookies': {'Forward': 'none'}, 'QueryStringCacheKeys': {'Quantity': 0}, 'QueryString': False}, 'MaxTTL': 31536000, 'SmoothStreaming': False, 'DefaultTTL': 86400, 'AllowedMethods': {u'Items': ['HEAD', 'GET'], u'Quantity': 2, u'CachedMethods': {u'Items': ['HEAD', 'GET'], u'Quantity': 2}}, 'MinTTL': 0, 'Compress': False}, u'IsIPV6Enabled': True, u'ViewerCertificate': {u'SSLSupportMethod': 'sni-only', u'MinimumProtocolVersion': 'TLSv1.1_2016', u'ACMCertificateArn': 'arn:aws:acm:us-east-1:1234567890:certificate/XXX', u'Certificate': 'arn:aws:acm:us-east-1:1234567890:certificate/XXX', u'CertificateSource': 'acm'}, u'CustomErrorResponses': {'Items': [{'ErrorCode': 403, 'ResponsePagePath': '/index.html', 'ResponseCode': '200', 'ErrorCachingMinTTL': 300}], 'Quantity': 1}, u'Aliases': {'Items': ['ourdomain.ourco.com'], 'Quantity': 1}, u'CallerReference': '1519340531311', u'CacheBehaviors': {'Quantity': 0}, u'HttpVersion': 'http2'}: An error occurred (InvalidArgument) when calling the UpdateDistribution operation: The parameter Field level encryption id is required.",
"response_metadata": {
"http_headers": {
"connection": "close",
"content-length": "301",
"content-type": "text/xml",
"date": "Fri, 25 May 2018 17:26:22 GMT",
"x-amzn-requestid": "be68c1fd-6040-11e8-b867-bd8b2f06ee63"
},
"http_status_code": 400,
"request_id": "be68c1fd-6040-11e8-b867-bd8b2f06ee63",
"retry_attempts": 0
}
}

# Fixed code
def validate_cache_behavior(
    self, config, cache_behavior, valid_origins, is_default_cache=False
):
    if is_default_cache and cache_behavior is None:
        cache_behavior = {}
    if cache_behavior is None and valid_origins is not None:
        return config
    cache_behavior = self.validate_cache_behavior_first_level_keys(
        config, cache_behavior, valid_origins, is_default_cache
    )
    cache_behavior = self.validate_forwarded_values(
        config, cache_behavior.get("forwarded_values"), cache_behavior
    )
    cache_behavior = self.validate_allowed_methods(
        config, cache_behavior.get("allowed_methods"), cache_behavior
    )
    cache_behavior = self.validate_lambda_function_associations(
        config, cache_behavior.get("lambda_function_associations"), cache_behavior
    )
    cache_behavior = self.validate_trusted_signers(
        config, cache_behavior.get("trusted_signers"), cache_behavior
    )
    cache_behavior = self.validate_field_level_encryption_id(
        config, cache_behavior.get("field_level_encryption_id"), cache_behavior
    )
    return cache_behavior