Using AWS S3 Virtual Hosting on the Web
Attaching FQDN to AWS S3 Bucket. This approach only support HTTP and does not support HTTPS.
Yes, it is possible to attach a Fully Qualified Domain Name (FQDN) to an AWS S3 bucket, similar to what you might do with Cloudflare R2. This process is known as "virtual hosting" for S3 buckets. Here's how you can set it up:
-
Create an S3 bucket: The bucket name must exactly match the FQDN you want to use. For example, if you want to use
bucket.example.com, your bucket name should bebucket.example.com. -
Configure the bucket for static website hosting: Enable static website hosting in the bucket's properties and set up your index and error documents.
-
Set up DNS: Create a CNAME record in your DNS settings that points your domain to the S3 website endpoint. The endpoint format is typically:
<bucket-name>.s3-website-<region>.amazonaws.com.For example, if you're using the Europe (Frankfurt) region (
eu-central-1), your CNAME record should look like this:Type: CNAME Name/Host: bucket.example.com Value/Target: bucket.example.com.s3-website.eu-central-1.amazonaws.com TTL: 3600 (or as preferred)This will allow you to access your content via
http://bucket.example.com. Note thathttps://access will not be available.A bit better approach is to use directly the Amazon S3 regular endpoint relevant to your region. So according the above example your CNAME record should look like this:
Type: CNAME Name/Host: bucket.example.com Value/Target: s3.eu-central-1.amazonaws.com TTL: 3600 (or as preferred)This allows you to access your bucket's content via
https://bucket.example.comin an insecure way. However, it may be sufficient for your web app to load files without running into CORS issues caused by HTTPS-to-HTTP requests. Note that in this setup, accessing the root URL directly will result in an AccessDenied error - even ifindex.htmlis present. Therefore, you must specify the full path to the file, such ashttps://bucket.example.com/index.html. -
Update bucket policy: Ensure your bucket policy allows public read access to the objects if you're hosting a public website.
-
Upload your content: Add your files to the S3 bucket.
Important considerations:
-
This method works well for subdomains (like
bucket.example.com) but for root domains (example.com), you'll need to use Amazon Route 53 as your DNS provider. -
S3 website endpoints don't support HTTPS by default. If you need HTTPS, you should use Amazon CloudFront in front of your S3 bucket. Always follow security best practices when setting up bucket policies.
-
If you're using Cloudflare as your DNS provider, you can enable the Proxied option to make HTTPS connections available.
For more information, you can refer to the AWS documentation on Website Endpoints and Getting Started with S3.
