Reputation: 395
Cache behaviour setting, i use
s3/*
to redirect request to s3 folder, but i don't want to place my images under a folder named s3 but right under s3 bucket to redirect like this:
xxxx.cloudfront.com/s3/images/1.png -> bucket_name/images/1.png
not
xxxx.cloudfront.com/s3/images/1.png -> bucket_name/s3/images/1.png
Please help to show me how to config like this.
Upvotes: 16
Views: 10323
Reputation: 16865
You can do this with lambdas here's the relevant lambda snippet.
exports.handler = (event, context, callback) => {
// this is the request we want to re-map
var request = event.Records[0].cf.request;
// the request has a 'uri' property which is the value we want to overwrite
// rewrite the url applying your custom logic
request.uri = 'some custom logic here to rewrite the url';
// quit the lambda and let the request chain continue
callback( null, request );
};
Upvotes: 19
Reputation: 270224
I don't think this is possible. An Origin Path can redirect to a subdirectory, (eg index.htm
-> production/index.htm
) but CloudFront can't strip out path portions.
See documentation: Origin Path
Some options:
s3
s3/
at the front of your filenames (and actually use the full path)Upvotes: 11
Reputation: 6525
Unfortunately this is not possible. Cloudfront will map the exact request path back to the origin. The only option it provides for manipulating the origin path is to add a prefix - it does not permit removing anything from the path.
Origin Path has details on the Origin path setting - but you'll see from that page there is no option to remove any part of the Request Path.
Upvotes: 2