I’ve been a serverless evangelist since the start of a new chapter in form of my company Datavizz. As a startup, you face a lot of challenges that you need to survive. One of those challenges and something that we do very first is finding a web hosting company that could give us the best rates to host our websites. Well, Why do you want to pay, when you can host your website for free???
Let me show you how I’ve been running my website with 0$
for the last two years.
My choice of platform is [AWS](http://aws.amazon.com/)
to run my Serverless
Platform.
Create an S3 Bucket
- Sign in to the AWS Management Console and open the Amazon S3 console
- Choose Create bucket
- The Create bucket wizard opens to the Name and region page.
- In Bucket name, enter a DNS-compliant name for your bucket.
The bucket name must:- Be unique across all of Amazon S3.
- Be between 3 and 63 characters long.
- Be without uppercase characters.
- Start with a lowercase letter or number
- In Region, choose the AWS Region where you want the bucket to reside.
- Choose Create
Note: You can also use aws cli to create a s3 bucket
aws s3api create-bucket --bucket my-bucket --region us-east-1
Enable Static Website Hosting
- Choose Properties.
- Choose Static website hosting.
- Choose to Use this bucket to host a website.
- Enter the name of your index document. The index document name is typically index.html.
- sample HTML file
<!DOCTYPE html>
<html>
<body>
<h1>Static Hosting on S3</h1>
<p>This site is hosted on s3 bucket</p>
</body>
</html>
- Upload static files to s3
aws s3 cp index.html s3://mybucket/index.html
- Edit Block Public Access Settings
- Go to block public access settings of your s3 bucket
- Clear Block all public access, and choose Save.
- In the confirmation box, enter confirm, and then choose Confirm.
- Choose the bucket that you have configured as a static website.
This should be enough if you want to host a website for your development or personal website.
But if you are running a production-grade website, I would recommend to setup CloudFront
up a CDN for your website which would further optimize the website.
Setting up your Cloudfront Distribution
- Search for
Cloudfront
service from your AWS Console - Click on
Create Distribution
- Since we are using
Web
we would be clicking onGet Started
along with that option. - Select your S3 Bucket as
Origin Domain
- If you have your
index.html
in the root directory of your S3 bucket, you can ignore putting information inOrigin Path
. - In Cache Settings you can keep things as default.
- Let’s go into
Distribution Settings
- Choose
Price Class
very wisely, because it would be the reason for the major cost in your CDN distribution - Chose AWS WAF if you’ve set up something in it.
- CNAMEs – This is the main configuration in which you need to put your domain name which would be authorized to be served whenever a user tries to request for your website.
- You would also have to set up an SSL certificate for your CNAME. – You could follow that here
- Default Root Object you can specify as
index.html
if you are using the same.
- Choose
- Then hit
Create Distribution
which would help you to get your CloudFront setup done.
Once the Cloudfront status turns Deployed
and the state as Enabled
, It means that your Cloudfront distribution is ready to be used.
You can find Domain Name
in your CloudFront distribution, which would basically become your URL, you would have to redirect your traffic coming from your domain.
That’s all and my serverless website setup was ready.
Don’t forget to leave down your review and do give me your comments on what you would like to see next!