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)


Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Retry later