- Introduction
- Set up the core bucket
- Set up the redirect bucket
- Canonical tags and path redirects
- Create, delete, and deploy to buckets in the CLI
- Resources
We will use 2 buckets to cover the needs for HTTPS security, automatic redirection to the canonical site, and higher search engine ranking. The recommended setup is:
- Core bucket to store site content for the full domain
- Redirect bucket will foward apex domain requests to the core bucket
- Apex domain:
example.com
- Fully qualified domain:
www.example.com
It's tempting to set up DNS to use the apex domain of example.com
. This seems to create a simpler canonical base for all of your hyperlinks. An apex domain is created with a CNAME record. However, new DNS records can't be made from CNAME records.
For example, if you want to host email services on the apex domain, you won't be able to create the necessary MX records from a CNAME record.
It's better to start off all your hyperlinks with www.example.com
(or any other subdomain like app.example.com
). By using the www
subdomain, you have more flexibility in creating additional DNS records for common situations like:
- MX and SPF records for email services
- TXT records for domain validation
- Load balancing options to redirect traffic from subdomains. The "CNAME and A Name" combination records are tied to a raw IP address that can't be load balanced.
We will use the full domain www.example.com
for the core bucket and create a second bucket to redirect the apex domain to the full domain. This configuration avoids content duplication, which lowers ranking scores on search engines.
The core bucket will host your static website content. Replace example.com
below with the domain of your website.
- Log into the management console, search for S3
- "Create Bucket" button
- Bucket name:
example.com
- Region:
US West (N. California)
or other region closest to your upload source - Click "Next" button 2 times (skip "Configure options")
- Bucket name:
- "Configure options" screen
- Disable "Block all public access"
- Enable "Block public access through new ACLs"
- Enable "Block public access through any ACLs"
- Leave as disabled "Block new public bucket policies"
- Leave as disabled "Block any public bucket policies"
- Press "Next" button
- Disable "Block all public access"
- "Review" screen > "Create bucket" button
- Go back to the main bucket list, choose
example.com
- "Permissions" tab > "Bucket Policy" tab
- Add the public read policy below by pasting it into the policy editor:
- Replace the phrase
YOURBUCKETNAME
withexample.com
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AddPerm", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::YOURBUCKETNAME/*" } ] }
- Replace the phrase
- Press "Save" button
- Go back to the main bucket list, choose
example.com
- "Properties" tab > "Static Website Hosting" > Enable option for "Use this bucket to host a website"
- Index document:
index.html
- Error document:
error.html
- If React Router is handling 404s, you can use
index.html
- If React Router is handling 404s, you can use
- Index document:
- Press "Save" button
This separate bucket will redirect the apex domain to the core bucket that contains the site content.
- Log into the management console, search for S3
- Press "Create bucket" button
- Bucket name:
redirect-example.com
- Region:
US West (N. California)
or same as source bucket
- Bucket name:
- Press "Next" button 2 times (skip "Configure options")
- "Set permissions" > leave all defaults intact > "Next" button > "Create bucket" button
- Go back to the main bucket list, choose
redirect-example.com
- "Properties" tab > Static website hosting:
- Enable "Redirect requests" option
- Target bucket or domain:
www.example.com
- Press "Save" button
Although not required for a basic site, canonical tags can be added later to help boost search engine rankings. If you need Apache-style rewrite rules, S3 has a unique XML-based format. Both of these topics are covered in a separate guide.
You can create public buckets, delete buckets, and deploy new content using the terminal utilities.