CloudFront - 错误时的意外缓存行为

CloudFront - Unexpected caching behaviour on error

当我的源抛出错误时,我从 CloudFront 看到了一个奇怪的行为。

我的场景如下:

初始请求:

然后我对源进行更改以确保它抛出如下错误响应:

当发出另一个请求(发送 header if-none-match: "example-etag")时,我预计会发生以下情况:

我在第二个请求中实际看到的内容:

这是预期的行为吗?如果是,我如何让 CF 将错误转发给客户端?

多亏了凯文的评论,我才能够理解这实际上是预期的行为。

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html 的文档解释说:

If the origin is unreachable and minimum TTL is greater than 0, CloudFront serves the object that it got from the origin previously. To avoid this behavior, include the Cache-Control: stale-if-error=0 directive with the object returned from the origin. This causes CloudFront to return an error in response to future requests if the origin is unreachable, rather than returning the object that it got from the origin previously.

我可以确认在 Cache-Control header 中返回 stale-if-error=0 有效,并且错误已转达给用户。