Cloudfront issue

0

I have pushed the new images to my server. When I make a request to CloudFront, it fails to fetch the image from the origin because it is not cached before, and it throws multiple 301 redirects. However, after clearing the cache in CloudFront, I can see the new image. But again, CloudFront sends a request to the origin and gets the response. When I make a request for the first time, it fails, but after clearing the cache, it works. What could be the reason?

Thanks in advance!

質問済み 2ヶ月前189ビュー
1回答
0

The issue you are facing is likely due to the way CloudFront handles the initial request for an object that is not yet cached in the Edge Locations.

Here's what typically happens when you request an object from CloudFront for the first time:

1 - CloudFront receives the request and checks if the object is cached in the Edge Location closest to the client.
2 - If the object is not cached, CloudFront sends a request to the origin server (your server) to fetch the object.
3 - During this initial request to the origin server, CloudFront follows any redirects (301 or 302) that the origin server may respond with.
4 - Once CloudFront receives the final response from the origin server (after following any redirects), it caches the object in the Edge Location.
5 - CloudFront then serves the cached object to the client.\

The issue you are facing is likely caused by the 301 redirects that your origin server is sending during the initial request from CloudFront. Since CloudFront follows these redirects, it may be causing a failure or timeout before it can retrieve and cache the object.

If your origin returns a redirect status code (for example, 301 or 307), CloudFront doesn’t follow the redirect. CloudFront passes along the 301 or 307 response to the viewer, who can follow the redirect by sending a new request.

I recommend you to check How CloudFront processes HTTP 3xx status codes from your origin.

profile pictureAWS
回答済み 2ヶ月前
profile picture
エキスパート
レビュー済み 2ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ