36
votes

I have created the s3 bucket with some files. I created the CloudFront distribution with that S3 bucket as origin and it changed status to deployed.

When I curl CloudFront for any file I get:

<Error><Code>TemporaryRedirect</Code><Message>Please re-send this request to the specified temporary endpoint. Continue to use the original request endpoint for future requests.</Message><Bucket>MY-BUCKET</Bucket><Endpoint>MY-BUCKET.s3-eu-west-1.amazonaws.com</Endpoint><RequestId>...</RequestId><HostId>...</HostId></Error>

When I curl my S3 bucket for any file I get that file contents.

What am I doing wrong? How to force cloudfront to cache files so that clients don't need to get data from S3 directly?

2
Did you try the Curl right away when you got the deployed message ? - error2007s
@error2007s more than 3 hours it is deployed, but the message still persists - Kivan
What region is your bucket in? What is your bucket endpoint that you've specified in your CloudFront distribution? - Matt Houser
Try invalidating your CloudFront distribution. It's possible that the DNS S3 issue may be resolved, but the response has been cached by CloudFront. Or wait for the TTL to expire before retrying. - Matt Houser
global endpoints are deprecated so please a regional one. stackoverflow.com/questions/65142577/… - Anton

2 Answers

57
votes

Thx Matt Houser from comment to my first post!

It seems CloudFront cached my first requests to files when distribution wasn't fully ready (but it was in deployed state at that time, so beware!). I requested invalidation to all files which were in cache, it took some minutes, but after invalidation was done, all files were curled with http 200 using CloudFront url.

The problem became clear after the comment from Michael-sqlbot:

All buckets have at least two REST endpoint hostnames. In eu-west-1, they are example-bucket.s3-eu-west-1.amazonaws.com and example-bucket.s3.amazonaws.com. The first one will be immediately valid when the bucket is created. The second one -- sometimes referred to as the "global endpoint" -- which is the one CloudFront uses -- will not, unless the bucket is in us-east-1. Over a period of seconds to minutes, variable by location and other factors, it becomes globally accessible as well. Before that, the 307 redirect is returned. Hence, the bucket was not ready.

14
votes

Just to clarify a bit more if it happens to you, there's a few choices:

  • Either wait up to 24h for the changes to propagate fully.

  • Change your bucket location to the us-east-1 region.

  • But the easiest is probably to switch your CloudFront origin domain name from <bucket>.s3.amazonaws.com to <bucket>.s3-<region>.amazonaws.com

Go to your Distribution settings -> Origins and Origin Groups and edit the current origin

For example, with a bucket named stackoverflow in the us-west-2 region, it would become

stackoverflow.s3-us-west-2.amazonaws.com