CloudFront 自定义文件位置

CloudFront custom file location

所以这是我第一次使用 AWS 和服务器设置。我在 AWS 上配置了 S3 和 CloudFront。由于我的 CloudFront 的来源设置为我的 S3,我相信 S3 上的文件将通过 CloudFront

检索如下

S3 - https://s3-ap-southeast-1.amazonaws.com/testbucket/uploads/logo/UfB7wDrn9A5r.jpg

CloudFront - https://randomstring.cloudfront.net/uploads/logo/UfB7wDrn9A5r.jpg

然而,我想要实现的目标 - 可能看起来很遥远 - 是我的图像的 CloudFront 路径 -

https://randomstring.cloudfront.net/UfB7wDrn9A5r.jpg

所以基本上不管文件在 S3 中的路径是什么,我都希望文件仅存在于 CloudFront 的根目录中。这甚至可能吗?

irrespective of what the path of the file is in S3

无所谓,没有。这不是您可以使用 S3 and/or CloudFront 开箱即用的东西。

可以折叠存储桶中的 单个 路径,这样 /uploads/logo 的内容将出现在 CloudFront 分配的根目录中,但所有文件不在 /uploads/logo 中将无法通过 CloudFront 访问。

这是通过在 CloudFront 中设置 Origin Path 来完成的。

如果您使用 /uploads 作为原始路径,那么 /uploads/logo/* 中的文件在 CloudFront 中将显示为 /logo/*,但这听起来不像是您的预期结果。

任何其他方式都需要 CloudFront 和 S3 之间的中间系统来 "hunt" 所需的资源,这将是低效且耗时的,更不用说文件名冲突的可能性了。