CloudFlare: CDN configuration for AWS S3 website hosting
Tags: aws, cdn, cloudflare
Published: 2019-09-23 10:49:56

---
title: CloudFlare: CDN configuration for AWS S3 website hosting
published: true
tags: AWS,CDN,Cloudflare
canonical_url: https://rtfm.co.ua/en/cloudflare-cdn-configuration-for-aws-s3-website-hosting/
---

![](https://rtfm.co.ua/wp-content/uploads/2019/09/cloudflare-logo.png)Need to create a static website hosting using AWS S3 and attach CloudFlare CDN to it.

### AWS S3 bucket

Create a new bucket for your website with the same name as it will be used for your site, in this case, it will be _cdn.example.com_:

[![](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_122846.png "CloudFlare: настройка CDN для AWS S3")](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_122846.png)

Go to the _Properties_ and enable website hosting:

[![](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_123017.png "CloudFlare: настройка CDN для AWS S3")](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_123017.png)

Go to the _Permissions_, in the _Bucket Policy_ enable full access to this bucket:

```
 {
    "Version": "2012-10-17",
    "Id": "MyPolicy",
    "Statement": [
        {
            "Sid": "PublicReadForGetBucketObjects",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::cdn.example.com/*"
        }
    ]
}
```

[![](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_123416.png "CloudFlare: настройка CDN для AWS S3")](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_123416.png)

Let’s check it now.

Create a new file and upload it to the bucket:

```
$ aws --profile bm-backend s3 cp index.html s3://cdn.example.com
upload: ./index.html to s3://cdn.example.com/index.html
```

Open it using bucket’s URL:

```
$ curl http://cdn.example.com.s3-website.us-east-2.amazonaws.com
TestCDN
```

### CloudFlare CDN configuration

After registration – go to the _Add Site_:

[![](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_122211.png "CloudFlare: настройка CDN для AWS S3")](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_122211.png)

CloudFlare supports two types of configuration – full when DNS for a whole domain will be changed thus it will be served totally bu CloudFlare DNS, and partial – when you can configure only one subdomain.

The second one requires to have a Business or Enterprise plan, and while we are waiting for our Enterprise plan to be enabled – let’s use the Full configuration.

Add a domain:

[![](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_122547.png "CloudFlare: настройка CDN для AWS S3")](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_122547.png)

Chose your plan here, for now – Trial, Enterprise will be enabled after email to the support@:

[![](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_122617-1.png "CloudFlare: настройка CDN для AWS S3")](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_122617-1.png)

CloudFlare will grab all the records existing for your domain:

[![](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_122709.png "CloudFlare: настройка CDN для AWS S3")](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_122709.png)

And you can create here a new subdomain for your CDN, for example, _cdn.example.com_ with the CNAME record type and set your bucket’s URL:

[![](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_123609.png "CloudFlare: настройка CDN для AWS S3")](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_123609.png)

As the last step – CloudFlare tell us which DNS needs to be set for our domain:

[![](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_123637.png "CloudFlare: настройка CDN для AWS S3")](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_123637.png)

Go to your domain registrar and update its DNS:

[![](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_124546.png "CloudFlare: настройка CDN для AWS S3")](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_124546.png)

Wait a couple of minutes and check:

```
$ whois example.com | grep Name
Domain Name: example.com
Name Server: cass.ns.cloudflare.com
Name Server: lloyd.ns.cloudflare.com
```

Check in the CloudFlare:

[![](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_125040.png "CloudFlare: настройка CDN для AWS S3")](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_125040.png)

And by using, for example, this service – [https://checkforcloudflare.selesti.com](https://checkforcloudflare.selesti.com):

[![](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_125129-1.png "CloudFlare: настройка CDN для AWS S3")](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_125129-1.png)

### SSL

The last thing to do is to update a bit SSL – enable HTTP to HTTPS redirect:

[![](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_125521.png "CloudFlare: настройка CDN для AWS S3")](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_125521.png)

CloudFlare uses its own certificate but you are able to upload an additional one:

[![](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_125611.png "CloudFlare: настройка CDN для AWS S3")](https://rtfm.co.ua/wp-content/uploads/2019/09/Screenshot_20190920_125611.png)

Done.

### Similar posts
 
- <small>07/17/2019</small> [AWS: S3 Cross-Region Replication with DeleteMarkers set up](https://rtfm.co.ua/en/aws-s3-cross-region-replication-configuration-and-objects-deletemarkers-replication/)
- <small>09/05/2018</small> [AWS: CloudFormation – создание S3 Website hosting и CloudFront distribution](https://rtfm.co.ua/aws-cloudformation-sozdanie-s3-website-hosting-i-cloudfront-distribution/)  
- <small>11/27/2018</small> [AWS: CloudFormation – S3 корзина для логов Application Load Balancer](https://rtfm.co.ua/aws-cloudformation-s3-korzina-dlya-logov-application-load-balancer/)