Hosting your website for free

Alex Broadbent
5 min readAug 8, 2023

I’ll show you how I host my website for free using AWS S3 and Cloudflare.

In order to start hosting your static website, you will need to set up accounts for:

Create the S3 Buckets in AWS

Once in AWS, head to the Amazon S3 console. Create 2 buckets, one for your full domain name and one for the top-level name. For example, and

We’re going to use the top-level name to store all our files in and we will redirect the bucket prefixed with www. to redirect to the top-level name bucket.

First, create the top-level bucket and select ACLs enabled under the Object Ownership

Then uncheck the Block all public access setting and check the acknowledgement at the bottom, we will later scope the access to the bucket so don’t worry about the warnings.

Click the Create bucket button.

Setup Static Hosting

Go into the bucket and head to the Properties tab, then scroll to the bottom to Static website hosting:

Make a note of the Bucket website endpoint as you will need this later when setting up Cloudflare.

Set hosting to Enable and set the type to Host a static website, for the Index document use whatever the output of your website will be (most likely index.html) and if you have a error page you can specify it for the Error document - optional (this might be error.html or 404.html).

Go to the Permissions tab at the top, from here we’ll restrict only servers from Cloudflare to be able to read any files within the bucket. Scroll down to the Bucket policy and enter the following:

"Version": "2012-10-17",
"Statement": [
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "*",
"Condition": {
"IpAddress": {
"aws:SourceIp": [

Update the Resource field to be whatever your bucket ARN is (it’ll be listed at the top of the bucket policy editor), the list of IP addresses are published to Cloudflare so get the latest list here.

Create and Setup the www.-prefixed bucket

For the www.-prefixed bucket, create the bucket as before but without setting the public access or policy on the bucket, we are just going to use this to redirect to the other bucket.

To do this, go to the Properties tab on the bucket, under the Static website hosting section at the bottom, enable Redirect requests for an object type and set the Host name to your other bucket (for example,

At the bottom of the Properties tab, make a note of the Bucket website endpoint for this bucket too.

Setting up Cloudflare

Putting Cloudflare in front of your static website will ensure that the number of calls are reduced to the AWS S3 bucket which will reduce the cost of your website, mine so far has not cost anything but this can differ depending on how many users you have and if you have more dynamic content on your website.

Adding a site

Once in Cloudflare, click Add site and enter your domain name.

Select the Free plan at the bottom of the plans.

Cloudflare will fetch the current DNS records for your domain from the registrar. We can add in the records for pointing to our website in the S3 bucket.

Point Cloudflare at the S3 buckets

Add a CNAME record with the domain name (for example, and set the content to your Bucket website endpoint (found at the bottom of the Properties tab of your bucket).

You can also set your www-prefixed bucket up with the content of your equivalent Bucket website endpoint.

So your settings will look something like:

Update your domain registrar

Press Continue and then Cloudflare will give you the nameservers which you need to set on your domain registrar.

For me, this was in IONOS:

Ensuring SSL Certificates are setup

Under SSL/TLS, check that your encryption mode is set to Flexible.

This will ensure that your domain is marked as secure when viewing in a browser.

Automating your static website

For my website, I have a private repository in GitHub, which automatically deploys any changes when merged into the main branch.

Automatically Deploying to AWS S3

Here’s my GitHub Workflow for deploying the output of your build folder to the AWS S3 bucket. Ensure you setup an AWS Key ID and Secret Access Key for authentication and use the name of your bucket that you want to upload to.

name: deploy

- main

runs-on: ubuntu-latest
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
node-version: 18
cache: 'yarn'
- run: yarn install
- run: yarn run build
- uses: shallwefootball/s3-upload-action@master
aws_key_id: ${{ secrets.AWS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_bucket: ${{ secrets.AWS_BUCKET }}
source_dir: 'build'
destination_dir: ''

Extending the setup


You can add any number of subdomains to your website in the same way, for example my blog website ( is hosted through AWS and S3, which is setup exactly the same as my top-level domain above.

Email forwarding

Cloudflare also offers an email forwarding service, which will automatically set up handling email with your domain name and then forwarding it onto your personal email address. This means that routes through to my personal email address which keeps it private from the website.