Set up a domain for your S3 Bucket with Cloudflare​

Duc Ho
3 min readApr 21, 2019

The endpoint given by AWS S3 after your object have uploaded is really noisy and not friendly with user’s experience. So, how we can make it more friendly? In this tutorial, I will guide you the best simple magic.

Problem & Solution

Firstly, I would like to upload my image with name is 2ktest.jpg to my S3 Bucket, and after my image has uploaded successfully, I got an endpoint like this:

https://s3-ap-southeast-1.amazonaws.com/s3.ducmeit.me/2ktest.jpg

However, it’s really noisy and not friendly with the user’s experience.

My solution is I would like to change the current endpoint to my subdomain and with S3 object like this:

https://s3-ap-southeast-1.amazonaws.com/s3.ducmeit.me/2ktest.jpg

Prerequisites

  • You must have a Cloudflare account and your domain must be DNS to Cloudflare’s DNS was provided.
  • Prepare a subdomain for ALIAS to your S3 bucket endpoint, for example, s3.ducmeit.me

If you haven’t any experience with Cloudflare, please follow the instruction below

DNS to Cloudflare

  1. Setup a Cloudflare and enter your domain name for setup.
  2. Go to your domain name’s management and use custom domain name server for DNS to Cloudflare’s name servers has given at the first step.

For example, I got two name servers:

jean.ns.cloudflare.com | kirk.ns.cloudflare.com

And my domain was purchased from namecheap.com and I would like to change my nameservers to Cloudflare’s Nameservers at above.

Click custom DNS and enter Cloudflare’s nameservers and save it

You may want to reference from document’s Namecheap for change DNS of your domain at here: https://www.namecheap.com/support/knowledgebase/article.aspx/767/10/how-to-change-dns-for-a-domain

Setup S3 Bucket

For require to ALIAS a domain to your S3 bucket, you must set the name of S3 bucket equal with your domain name you want to ALIAS to it.

It’s mean I must to set a Bucket with name s3.ducmeit.me

ALIAS Your Domain

After your domain has DNS to Cloudflare and managed by them. We would like to use DNS services to create an ALIAS domain to your s3 bucket.

Depend on your S3 Bucket’s regional, we will ALIAS with difference hostname.

For example, my S3 bucket is currently hosted by Singapore regional with name ap-southest-1

We can ALIAS like this:

  1. Select CNAME
  2. Enter wildcard name is s3 (for s3.ducmeit.me)
  3. Enter Singapore regional endpoint of the AWS S3: s3-ap-southeast-1.amazonaws.com
  4. You may want to enable or disable the Cloudflare Proxy to your domain
The result after add record successfully

That’s all

Let’s try to upload an object and access to it with your domain.

Thank you, if you have any question or comment please lets it at below.

AWS S3 Endpoints

Here are some endpoints you may want to copy if you don’t know:

The best simple way to find your endpoint that is look up to the Object URL of your S3 object:

The S3 endpoint is shown up here

--

--