We are facing an issue with an AWS CloudFront distribution where we have run out of behaviors. Our current configuration creates a separate behavior for each page or group of pages that requires specific caching settings. For example:
- Behavior 0:
/page-1
- Behavior 1:
/page-2
- Behavior 2:
/articles/*
We know that CloudFront allows the use of wildcards in path patterns, such as /articles/*, but ideally, we’d like to group multiple static pages under a single behavior, like this:
- Behavior 0:
/page-1 /page-2
- Behavior 1:
/articles/*
However, CloudFront does not seem to support multiple path patterns (e.g., /page-1 and /page-2) in a single behavior.
Is it possible to group multiple specific static pages under a single behavior in CloudFront?
We suspect that grouping unrelated paths into a single behavior is not directly possible, but we’d love to confirm if we’re missing something. Are there better strategies for managing behaviors in CloudFront to handle a growing number of static pages?
From the documentation, your options to have multiple page listed on a single behavior seems to be limited…
However, you could use a Lambda@edge attached to the default behavior on the origin request and update your origin from your path value.
Another option would be to use CloudFront KeyValueStore and a CloudFront Function. If you’re able to migrate to this approach, you will be able to add any routes easily in the store without having to modify/redeploy CloudFront with each new path.