我们使用 S3 在线存储文件。为了降低成本,可以使用提前已知的路径按需生成其中许多文件。
是否可以让 S3 存储桶将丢失的对象请求重定向到我预先配置的端点(然后可以按需生成和提供文件)?
例如,对 http://bucket1.s3.amazonaws.com/path2/file3.jpg 的请求将暂时重定向 (307) 到 http://mydomain.com/missing_s3_obj/bucket1/path2/file3.jpg .
最佳答案
您可以使用 RoutingRules
将 S3 重定向到您的域,如 Example 3 of Configure a Bucket for Website Hosting 中所述来自 S3 文档。我相信它准确地描述了您的情况。
<RoutingRules>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<HostName>mydomain.com</HostName>
<ReplaceKeyPrefixWith>missing_s3_obj/bucket1/</ReplaceKeyPrefixWith>
<HttpRedirectCode>307</HttpRedirectCode>
</Redirect>
</RoutingRule>
</RoutingRules>
关于http - 让 Amazon S3 在缺少对象请求时重定向到我的端点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10839125/