Cloudfront:设置与Origin的s3路径差异

Cụt*_*ánh 4 cdn amazon-s3 amazon-web-services amazon-cloudfront

缓存行为设置,我使用

s3/*
Run Code Online (Sandbox Code Playgroud)

将请求重定向到s3文件夹,但我不想将我的图像放在名为s3的文件夹下,而是在s3存储桶下以这种方式重定向:

xxxx.cloudfront.com/s3/images/1.png  -> bucket_name/images/1.png
Run Code Online (Sandbox Code Playgroud)

xxxx.cloudfront.com/s3/images/1.png  -> bucket_name/s3/images/1.png
Run Code Online (Sandbox Code Playgroud)

请帮我示范如何进行配置。

xen*_*ide 11

您可以使用lambda做到这一点这是相关的lambda代码段。

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 );    
};
Run Code Online (Sandbox Code Playgroud)


Joh*_*ein 8

我不认为这是可能的。源路径可以重定向到子目录(例如index.htm-> production/index.htm),但 CloudFront 无法去除路径部分。

请参阅文档:原点路径

一些选项:

  • 使用单独的分发而不是前缀路径 s3
  • 只需放在s3/文件名的前面(实际上使用完整路径)