DEV Community

Wilson McCoubrey
Wilson McCoubrey

Posted on

Setup Custom Domain for S3 Static Website with Cloudflare CDN

Overview

This post briefly describes a little bit of what I learned when looking to setup a custom domain and CDN for a static website hosted on S3.

TLDR

Bucket name needs to match custom domain. E.g. to setup a custom domain of wilsonmccoubrey.com, bucket name must be wilsonmccoubrey.com

Assumptions

This quick guide assumes you have:

  • A static website running successfully inside a bucket in S3, accessible via the bucket url e.g. http://<bucket name>.s3-website-<region>1.amazonaws.com/
  • A domain setup in cloudflare and nameservers setup

Steps

Set bucket name correctly

When setting up your bucket, your bucket name must match the custom domain which you want to serve the site from. For example, to setup a custom domain of wilsonmccoubrey.com, bucket name must be wilsonmccoubrey.com. I originally made this mistake and received 'NoSuchBucketException' in the browser after setting up my domain.

Add CNAME Record to Cloudflare

Enable SSL (Optional, but recommended)


Top comments (0)