S3 and Cloudfront

29 January, 2021
Back

You can serve a website hosted in S3 from Cloudfront for your content to reach a speedy fast global audience.

  1. Spin up an S3 bucket and host 3 files in the following order.
/index.html
/error/error.html
/blocked/blocked.html
  1. Go to the Permissions tab and scroll down to bucket policy. Copy and paste this but replace the your-s3-bucket-name with your own.
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:ListBucket",
            "Resource": "arn:aws:s3:::your-s3-bucket-name"
        },
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Resource": "arn:aws:s3:::your-s3-bucket-name/*"
        }
    ]
}
  1. Once it's created, you can access your website with a link that looks something like this dz4255swmz0m4.cloudfront.net.
  2. Explore the rest of the settings by customizing your own error page and geo-restricted error page by using error.html and blocked.html.

Back