How To Add Google AdSense To Your Website
    How To Download Canvas as an image
    How To Embed Youtube Videos
    How To Host NodeJS Apps
    How To Host Static Websites On Amazon AWS EC2
    How To Host Static Websites On Amazon AWS S3
    How To Host Static Websites On GCP Cloud Storage
    How To Install Node.js
    How to Speed Up IntelliJ IDEA / Clion
    How to safely store API Keys

How To Host Static Websites On Amazon AWS S3

Updated: 2022-02-21

In this tutorial we are deploying a static website to Amazon AWS S3. Suppose your host name is

Local Box

Install CLI

On Mac:

$ brew install awscli

On Ubuntu/Debian:

$ sudo apt install awscli


$ aws configure
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json


$ aws s3 sync . s3://my-bucket

Note that if you delete some local files, this will not delete the corresponding remote files in the bucket. To delete those, add --delete

$ aws s3 sync --delete . s3://my-bucket

If you regenerate local files using some static site generator like Jekyll or Hexo, the newly generated files will have different timestamp, so by default everything will be uploaded. To decide whether to upload a file by its size instead, use --size-only

$ aws s3 sync --delete --size-only . s3://my-bucket

To find more options, call help

$ aws s3 sync help

Amazon AWS S3 Console

Go to console:

Create Bucket

Click Create Bucket, fill in Bucket Name.

Note: if you are not using Route 53, make sure you use the exact domain name as the bucket name, e.g., otherwise you will see the follow error:

404 Not Found

- Code: NoSuchBucket
- Message: The specified bucket does not exist
- BucketName:
- RequestId: ......
- HostId: ......

Enable Website Hosting

Modify bucket properties, Static Website Hosting section, click Enable website hosting, add Index Document, e.g. index.html, save.

Add Bucket Policy

Click Add bucket policy, add this to the text area, make sure to change the bucket name in Resource:

  "Version": "2012-10-17",
  "Statement": [
      "Sid": "PublicReadForGetBucketObjects",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "*"


Add a CNAME record:

test    CNAME


Open your browser, point to course replace with your real host name)

Trouble Shooting

ERROR: NoSuchKey


404 Not Found

- Code: NoSuchKey
- Message: The specified key does not exist.
- Key: index.html
- RequestId: ......
- HostId: ......

Reason: the specified index or error file is not there. Double check your settings and the files in the bucket.

ERROR: NoSuchBucket


404 Not Found

- Code: NoSuchBucket
- Message: The specified bucket does not exist
- BucketName:
- RequestId: ......
- HostId: ......

Reason: the bucket name does not match your domain name; set your bucket name to

ERROR: NoSuchWebsiteConfiguration


404: Not Found

- Code: NoSuchWebsiteConfiguration
- Message: The specified bucket does not have a website configuration
- BucketName:
- RequestId: 1C661A36E8D467EB
- HostId: q7grWdZIyMJOw1Oc94nrrNteMpQu52Q154rLHHP02Tr9FAt8U71LAkUeVS0EuA+Y9JoHket/O2k=

Reason: Static Website Hosting is not enabled.

Advantages Over Hosting On EC2

  • low maintenance, no need to monitor the health of the instance
  • easy update:
    • EC2: if use git, step 1, local push; step 2, ssh to EC2 instance; step 3, pull
    • S3: use aws s3 sync. Done.