Reputation: 1742
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?
Upvotes: 44
Views: 23222
Reputation: 1
Switch the CloudFront origin domain name from .s3.amazonaws.com to .s3-.amazonaws.com worked for me!
you can get this from the RegionalDomainName attribute. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-s3-bucket.html
Upvotes: 0
Reputation: 35846
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
Upvotes: 20
Reputation: 1742
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.
Upvotes: 64