Host a Free Static Website with AWS CloudFront and S3


Free Hosting with AWS CloudFront and S3



 
:check_mark:

AWS CloudFront Website Demo:

AWS CloudFront and S3 Website

     

AWS Services in this Stack

Time Period

Free Tier Limits / Pricing

Amazon CloudFront

used as content delivery network (CDN)

Each month

Always Free

Free 1 TB of data transfer out (approx 1million pageviews of 1MB pages)

Free 10,000,000 HTTP or HTTPS Requests

Amazon S3

used for hosting - web pages (file) storage on cloud

cost will be negligible for a small project since we will be caching pages with CloudFront cache to minimize S3 read requests

Each month

12 Months Free

Free 5 GB of Standard Storage

Free 20,000 Get Requests

Free 2,000 Put Requests

After 12 months

$0.0004 per 1000 GET Requests

$0.023 per GB storage cost

Amazon Route 53

used as Domain Name Service (DNS)

optional - for custom domain

Paid

Domain Name Registration (~ $12 for 1 year)

Hosted Zone ($0.5 per month)

AWS Certificate Manager

used to generate SSL certificate - one time

Always Free

Free


Steps to Host your Website with AWS:

  1. AWS Developer Guide for deploying static website on CloudFront. - AWS Guide

  2. Create a Free AWS account - AWS Console.

    1. You will have to provide a Credit card and phone number to validate your identity.

 

S3 Configuration:

  1. Go to AWS S3 Service from the console - AWS S3 Console

    1. Create Bucket - provide name and region (us-east-ohio has one of the low pricing $0.0004)

    2. Uncheck - Block Public access checkbox

    3. Enable Bucket versioning

    4. Other options default - disabled encryption and object lock

    5. Create Bucket

  2. Upload Files to the S3 bucket

    1. Upload a .html file having html / css / js code.

    2. Select Standard Storage class - to minimize cost.

    3. Leave other options default / turned off.

    4. If you copy the item URL and hit in the browser, it will give Access Denied since we need to set the bucket policy so that only CloudFront can access the S3 bucket objects.

 

CloudFront Configuration:

  1. Go to AWS CloudFront from the console - AWS CloudFront

    1. Create a CloudFront distribution

    2. Origin domain for CloudFront will be the S3 bucket we created above.

    3. Origin Access - Create Origin Access Control policy using Create button - Select Sign requests option required to restrict S3 access only to CloudFront.

    4. Caching Policy - Caching Optimized for now (this will cache the S3 items for 1 day in CloudFront cache, after 1 day it will again hit the S3 origin to get fresh copy of the file item)

    5. Leave other default settings - Do not enable Origin shield - it will add to cost as it is not free

    6. Price Class - Select North America and Europe for least cost. Do not select more edge locations as the price will increase based on more edge locations of CDN.

    7. Create Distribution

  2. After few minutes the distribution will be deployed and you can hit the distribution domain name in browser:

    1. Our Demo CloudFront : d366ztwgqbpglu.cloudfront.net

    2. You will get access denied error because we need to update S3 policy to allow access to CloudFront

    3. Copy the ARN and distribution name for your CloudFront

 

S3 Bucket Access Policy:

  1. Go back to S3 bucket in AWS console

    1. Select the Permissions Tab

    2. Here we need to provide below bucket policy to allow access only to your CloudFront

    3. Update you S3 bucket name and CloudFront ARN in the JSON

  2. Now hit your CloudFront with Page URL

    1. Demo: AWS CloudFront and S3 Website

    2. It should work now!

 

Congrats you are online on Amazon CloudFront!!

  1. Comment below and let us know if you face any issues..



Bucket Policy:
1{ 2 "Version": "2012-10-17", 3 "Statement": [ 4 { 5 "Sid": "Statement1", 6 "Effect": "Allow", 7 "Principal": { 8 "Service": "cloudfront.amazonaws.com" 9 }, 10 "Action": "s3:GetObject", 11 "Resource": "arn:aws:s3:::free-cloud-stacks-bucket/*", 12 "Condition": { 13 "StringEquals": { 14 "AWS:SourceArn": "arn:aws:cloudfront::019971473017:distribution/EW2RIIZHICBF1" 15 } 16 } 17 } 18 ] 19}

 

S3 images:












CloudFront Images:















S3 Bucket Policy:








Hosted Page:











Credits: Icons from Free3dIcons


Comments

Post a Comment

Popular posts from this blog

How to use AWS DynamoDB as Free Database in Javascript Serverless Webpages