How to set up a Cloudflare CDN for Amazon S3

Considering that Cloud technology is constantly expanding, and currently, telecommunications companies are offering increasingly advantageous Cloud solutions, today we will present a solution for storing a simple/static website with minimal financial input. The same solution is also suitable for accelerating an existing website. We will need a domain and a Registry for our website, with ROTLD being the registry for .ro domains.

Additionally, an account with Cloudflare and Amazon is required.

Registry Cloudflare Amazon

First, we will need to configure the settings in ROTLD for the NS (Nameservers) from Cloudflare:

Rotld NS Cloudflare

What is CDN ?

A Content Delivery Network (CDN) is a geographically dispersed network of nodes. Each node/server in the CDN (also known as an Edge Server) in this network contains the static files present on a website.

Content Delivery Network

Amazon S3

We’ll create a new S3 registration (bucket) in Amazon account. Here we’ll keep all the files that we want to be access and/or serve to our server.

Amazon S3 Bucket

We enter the Bucket name (we recommend cdn.example.com, where “example.com” is the desired name), and we check the Versioning option.

During configuration, we uncheck the “Block all public access” option because we want all users to be able to access the resources.

In the Properties section, we activate “Static Website Content”:

S3 Static Website

In the Permissions section, for the Bucket Policy, we enable full access.

S3 Permissions
{
    "Version": "2012-10-17",
    "Id": "ExempluS3Policy",
    "Statement": [
        {
            "Sid": "PublicReadForGetBucketObjects",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::cdn.exemplu.ro/*"
        }
    ]
}


We upload some files and test them with a browser.

Cloudflare configuration

It’s time to move to Cloudflare and configure the CDN, adding a new CNAME record:

Cloudflare DNS management

As a final step, we ensure that the Nameservers (NS) are pointing to Cloudflare:

Cloudflare NS

Please wait a few minutes and test that everything is working fine on “whatsmydns“:

Whatsmydns

You can also use the “checkforcloudflare” service.

Check for Cloudflare

Congratulations, you have a free CDN that meets all the prerequisites.

HTML | CSS | JavaScript | PHP | Codeignitor | Sql | Docker | DevOps | Cloudflare | cPanel | Wordpress |
HTML | CSS | JavaScript | PHP | Codeignitor | Sql | Docker | DevOps | Cloudflare | cPanel | Wordpress |
Scroll to Top