如何将每个请求从 CloudFront 转发到源 S3

How to forward every request from CloudFront to origin S3

我读了

If you configure CloudFront to forward all headers to your origin for a cache behavior, CloudFront never caches the associated objects. Instead, CloudFront forwards all requests for those objects to the origin. In that configuration, the value of Minimum TTL must be 0.

现在我将最小 TTL 设置为 0 并尝试转发所有 headers 我从 CloudFront 收到错误消息: 您不能选择转发所有具有 S3 来源的 headers。

我如何让每个请求都检查 s3 来源(以便存储桶中的新 objects 立即在 CloudFront 中更新)

除非您的存储桶名称与域名完全匹配,否则您无法将所有 header 转发到 S3,即使这样也不推荐这样做。

相反,将最小 TTL、默认 TTL 和最大 TTL 全部 设置为 0。

当 object 存储在未定义 Cache-Control 值的存储桶中时,将使用默认 TTL。当 Cache-Control 指定 non-zero TTL 时使用最大 TTL(CloudFront 将出于内部目的将任何更大的值 down 强制为最大 TTL)。除极少数情况外,最小 TTL 应始终设置为 0。

请注意,更改这些值需要失效,否则缓存中已有的 object 可能会使用先前的值。


或者,在将 objects 写入存储桶时,将 s-maxage=0 添加到 Cache-Control header 值并确保最小 TTL 设置为 0。