AWS CloudFront returns http 307 when origin is S3 bucket
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
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.