0
votes

I am working on a Lambda Function written in python and using boto3 to call AWS APIs.
Work of lambda function as follows -

  1. Get the CloudFront Distribution list.
  2. Get the CloudFront Distribution ID.
  3. Get the CloudFront Distribution Config of those distribution which older than 60 minutes.
  4. Create a JSON file of CloudFront Distribution Config.
  5. Read the JSON file and make a dictionary array to pass in CF update API.
  6. Call Update Distribution API and pass the required parameters.

Reference Document is - AWS Boto3

Now the problem is, the update API giving an error to me as far as the requested data is correct.

Please find my python lambda function code link - Lambda function to disable and delete CloudFront destribution

Here is the error I am getting while updating (disable) CloudFront distribution via update API-

Parameter validation failed:
Missing required parameter in DistributionConfig: "CallerReference"
Missing required parameter in DistributionConfig: "Origins"
Missing required parameter in DistributionConfig: "DefaultCacheBehavior"
Missing required parameter in DistributionConfig: "Comment"
Missing required parameter in DistributionConfig: "Enabled"
Unknown parameter in DistributionConfig: "ETag", must be one of: CallerReference, Aliases, DefaultRootObject, Origins, OriginGroups, DefaultCacheBehavior, CacheBehaviors, CustomErrorResponses, Comment, Logging, PriceClass, Enabled, ViewerCertificate, Restrictions, WebACLId, HttpVersion, IsIPV6Enabled
Unknown parameter in DistributionConfig: "DistributionConfig", must be one of: CallerReference, Aliases, DefaultRootObject, Origins, OriginGroups, DefaultCacheBehavior, CacheBehaviors, CustomErrorResponses, Comment, Logging, PriceClass, Enabled, ViewerCertificate, Restrictions, WebACLId, HttpVersion, IsIPV6Enabled
Unknown parameter in DistributionConfig: "ResponseMetadata", must be one of: CallerReference, Aliases, DefaultRootObject, Origins, OriginGroups, DefaultCacheBehavior, CacheBehaviors, CustomErrorResponses, Comment, Logging, PriceClass, Enabled, ViewerCertificate, Restrictions, WebACLId, HttpVersion, IsIPV6Enabled

The above error message shown the parameters are missing but I have checked the request has all the required parameters, I didn't understand why its giving error.

If someone has any solution for this please share or any other idea to disable and delete CloudFront distribution from AWS Lambda.

1
Try update_distribution(DistributionConfig=dist_list['DistributionConfig'], ...)jarmod

1 Answers

1
votes

The problem is that your dist_list variable is the returned value from calling cloudfrontclient.get_distribution_config(...). This is not actually the distribution config. It's a dictionary containing the distribution config.

Change your update call as follows:

dc = dist_list['DistributionConfig']
dist_update = cloudfrontclient.update_distribution(DistributionConfig=dc, ...)