Search code examples
amazon-web-servicesaws-lambdaamazon-cloudfront

Cloning Cloudfront distributions and listening to changes


I'm facing a quite odd problem. I want to clone my Cloudfront distribution, so that the cloned versions would listen to changes on the original. The problem I'm facing is that my original distribution has some Lambda functions in it's default Behavior. When I deploy changes to the original distribution, usually a new version of the lambda functions, I want it to change across all the cloned distributions. Otherwise the cloned distributions will keep using the old versions of those functions.

I'm wondering if someone else faced this problem, and if there is an automated way around this? I'm talking about hundreds of distributions.

I know how to clone a Cloudfront distribution, but couldn't find anything about adding those listeners.


Solution

  • You can use AWS Config and CloudWatch events to get notifications when the primary cloudfront distribution is changed (here is a link). This requires some trial and error, but the process:

    • the main CloudFront distribution changes
    • AWS Config publishes an event to CloudWatch Events
    • CW Events calls a Lambda function
    • the function changes the other CloudFront distributions based on the main distribution's config

    On the other hand, I'd definitely go on the route of using IaaC tools, such as CloudFormation or Terraform. You can change the config in one place and they can take care of the rest.