First off, I much prefer Cloudflare’s R2 over Amazon’s S3 for a slew of reasons, but I found myself in a place where I needed to offload about 80Gb to AWS S3 bucket to be served under a subdomain, proxied by Cloudflare.
I ran into a problem where I could not get a properly configured AWS S3 bucket to serve its content when added to the Cloudflare proxied domain via a CNAME record. Unfortunately, all I got were 403 and 522 error messages. I’ve lost count over how many different ways I have double-checked existing setups with the one I was setting up, but not luck.
Wasted three hours debugging, reading through all the documentation and information in the forums until I figured out what the solution was. This note is nothing more than me writing this down for future Remkus and anyone else who stumbles upon this note.
Prerequisites
- We’re assuming you’re familiar with how to set up an AWS S3 Bucket to serve content.
- We’re als assuming you understand basic DNS setup of CNAME’s and the like
- Lastly, we’re also assuming you already have your site working within Cloudflare’s environment.
Time needed: 1 minute
Configure S3 Bucket in Cloudflare’s DNS properly
- Copy the S3 bucket public URL
Login into your S3 Console, find your bucket, and look at the bottom of the Properties tag. Right under the Static Website Hosting section you’ll find the bucket website endpoint. It will look something like this:
bucketname.example.com.s3-website.eu-central-1.amazonaws.com
- Change bucket website endpoint
The AWS endpoint documentation mentions sort of offhand that you may need to change this bucket website endpoint. And in my case, that’s what I needed to do.
bucketname.example.com.s3-website.eu-central-1.amazonaws.com
but this did work:bucketname.example.com.s3.eu-central-1.amazonaws.com
All that was needed was to remove the-website
part of the URL. - Add adjusted bucket website endpoint as CNAME in Cloudflare
Copy and paste adjusted website endpoint URL and paste it in the Target input field like so:
- Make sure you turn on Proxy
As can be seen in the above screenshot, you’ll need to make sure Cloudflare is proxying that S3 bucket for it all to work as intended.
Once you’ve done that, hit Save and all will be well.
Hope you don’t have to waste another three hours comparing every single setting in both AWS and Cloudflare 5 times over. Happy serving!
Leave a Reply