【问题标题】:Cloudfront: setting s3 path difference from OriginCloudfront:设置与 Origin 的 s3 路径差异
【发布时间】:2017-02-21 00:00:56
【问题描述】:
缓存行为设置,我用
s3/*
将请求重定向到 s3 文件夹,但我不想将我的图像放在名为 s3 的文件夹下,而是放在 s3 存储桶下,以便像这样重定向:
xxxx.cloudfront.com/s3/images/1.png -> bucket_name/images/1.png
不是
xxxx.cloudfront.com/s3/images/1.png -> bucket_name/s3/images/1.png
请帮我看看如何这样配置。
【问题讨论】:
标签:
amazon-web-services
amazon-s3
cdn
amazon-cloudfront
【解决方案1】:
您可以这样做with lambdas 这是相关的 lambda sn-p。
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 );
};
【解决方案2】:
我认为这是不可能的。源路径可以重定向到子目录(例如 index.htm -> production/index.htm),但 CloudFront 无法去除路径部分。
查看文档:Origin Path
一些选项:
- 使用单独的分发版,而不是在路径前加上
s3
- 只需将
s3/ 放在文件名的前面(并实际使用完整路径)
【解决方案3】:
很遗憾,这是不可能的。 Cloudfront 会将确切的请求路径映射回源。它为操作原始路径提供的唯一选项是添加前缀 - 它不允许从路径中删除任何内容。
Origin Path 包含有关 Origin 路径设置的详细信息 - 但您会从该页面看到没有删除请求路径任何部分的选项。