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?
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.