Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CloudFront Origin Path and Cache Behavior interaction

I have a CloudFront distribution set up to point to an S3 bucket. My S3 bucket has a versioned path for its files (so for example, http://example.s3.us-east-1.amazonaws.com/static/ui/v5.53.3/). I want to configure a cache behavior that only matches the /static/ui/* path, but I want all requests to my origin to have the path /static/ui/v5.53.3. I’ve tried to set my cache behavior’s Path Pattern to /static/ui/* and my origin path to /v5.53.3, but that doesn’t seem to work.

How can I configure this with CloudFront?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Origin path

If you want CloudFront to always request content from a particular directory in the origin, enter the directory path, beginning with a forward slash (/). Do not add a slash (/) at the end of the path. CloudFront appends the directory path to the origin domain name.

In your case, origin domain name is example.s3.us-east-1.amazonaws.com. So the request that your origin sees is example.s3.us-east-1.amazonaws.com/v5.53.3/*. This is why it doesn’t work.

In fact, as of May 2022, this is not possible to achieve without using Lambda@Edge. You’d have to do a custom URL rewrite in Lambda.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading