cloudposse / terraform-aws-cloudfront-cdn

Terraform Module that implements a CloudFront Distribution (CDN) for a custom origin.
https://cloudposse.com/accelerate
Apache License 2.0
99 stars 121 forks source link

Feature request: please support applying different cloudfront functions to different behaviors #73

Closed sjmiller609 closed 1 year ago

sjmiller609 commented 3 years ago

Have a question? Please checkout our Slack Community or visit our Slack Archive.

Slack Community

Describe the Feature

AWS CloudFront supports using a different cloudfront function for each Behavior. For example, a user may want to have /app go to one s3 bucket and / (default path) go do a different s3 bucket, and the user may want to apply different cloudfront functions for each Origin (which are routed to via Behaviors).

Expected Behavior

By default, apply function to all behaviors (support backwards compatibility), but add a new configuration to apply a function only to a specific Behavior.

Use Case

Users may want to apply different cloudfront functions depending on which Origin is selected. For example one Origin may require appending index.html when a directory is specified, for example S3 Origin, but another may require this is not done, for example when using API Gateway as an Origin.

Describe Ideal Solution

  function_association = [{
    event_type   = "viewer-request"
    function_arn = data.aws_cloudfront_function.viewer_request_homepage.arn
    # New optional attribute:
    target_origin_id = "homepage"
  },
  {
    event_type   = "viewer-request"
    function_arn = data.aws_cloudfront_function.viewer_request_application.arn
    # New optional attribute:
    target_origin_id = "application"
  }
  ]

Alternatives Considered

In the cloudfront function, conditional logic can be used to skip specific handling depending on which Origin would be selected.

Additional Context

If you deploy a cloudfront with functions and multiple origins, then you can select Behavior in the AWS console to see that an AWS user may select different cloudfront functions per Behavior.

sjmiller609 commented 1 year ago

I no longer care about this issue