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?
CodePudding user response:
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.