If you want to host a fully secure HTML website on AWS S3 with a custom domain from Hostinger, this guide will walk you through the process step by step. By following these instructions, you can ensure that your website is fast, reliable, and HTTPS-secured using AWS CloudFront.
Introduction
Hosting a website on AWS S3 is one of the most cost-effective and scalable ways to launch a static website. By integrating AWS CloudFront and SSL/TLS certificates, you can make your website secure (HTTPS) while ensuring fast content delivery globally.
In this guide, we will use Hostinger's custom domain and configure it with AWS CloudFront and Route 53 for proper domain resolution.
Prerequisites
Before we begin, ensure you have the following:
- An AWS account (Sign up at AWS)
- A registered domain with Hostinger
- A basic HTML website (index.html, CSS, and JS files)
- Some familiarity with AWS services (optional but helpful)
Step 1: Create an S3 Bucket
- Log in to AWS Console and navigate to S3.
- Click Create bucket.
- Enter the bucket name (it should be the same as your domain, e.g.,
yourdomain.com
). - Choose a region (e.g.,
us-east-1
). - Uncheck "Block all public access" and confirm.
- Click Create bucket.
Step 2: Upload Website Files
- Open the S3 bucket.
- Click Upload and add your website files (
index.html
,style.css
,script.js
, etc.). - Click Upload.
Step 3: Enable Static Website Hosting
- Go to the S3 bucket and open the Properties tab.
- Scroll to Static website hosting and click Edit.
- Select Enable and choose Host a static website.
- Enter:
- Index document:
index.html
- Error document:
error.html
(optional)
- Index document:
- Click Save changes.
- Copy the Bucket website endpoint (you'll use this later).
Step 4: Configure S3 Bucket Policy for Public Access
To make the website public, update the Bucket Policy:
- Open the Permissions tab.
- Click Edit under Bucket policy.
- Paste the following JSON policy:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::yourdomain.com/*" } ] }
- Click Save changes.
Step 5: Set Up CloudFront for Secure Hosting
- Go to CloudFront in AWS.
- Click Create distribution.
- Under Origin Settings:
- Origin domain: Select your S3 bucket website endpoint.
- Origin access: Choose Public.
- Click Create distribution.
- Copy the CloudFront domain name (e.g.,
d123xyz.cloudfront.net
).
Step 6: Obtain and Configure SSL Certificate
- Open AWS Certificate Manager (ACM).
- Click Request a certificate → Choose Public Certificate.
- Enter your domain (
yourdomain.com
,www.yourdomain.com
). - Validate via DNS.
- Attach this SSL certificate to your CloudFront distribution.
Step 7: Point Custom Domain to AWS (Hostinger DNS Settings)
- Log in to Hostinger and navigate to Domains > Manage.
- Click DNS Settings.
- Add a CNAME record:
- Host:
www
- Points to:
CloudFront URL
- TTL:
Automatic
.
- Host:
- Add an A record (for root domain
yourdomain.com
):- Host:
@
- Points to: CloudFront's IP.
- Host:
- Wait for DNS propagation (can take up to 24 hours).
Step 8: Test and Verify the Setup
- Open
yourdomain.com
in a browser. - If CloudFront is used, verify HTTPS is working.
- Run
nslookup yourdomain.com
to check DNS resolution.
FAQs
1. Can I use Route 53 instead of Hostinger DNS?
Yes, AWS Route 53 is recommended for better integration, but Hostinger DNS also works fine.
2. How much does it cost to host a static site on AWS S3?
AWS S3 static hosting is cheap. You pay for storage + requests + CloudFront bandwidth, which usually costs less than $1/month for small websites.
3. Why use CloudFront instead of direct S3 hosting?
- Enables HTTPS (SSL/TLS)
- Faster global content delivery
- Better security and DDoS protection
4. How long does it take for the domain to work?
DNS propagation takes a few minutes to 24 hours.
Final Thoughts
By following these steps, you have successfully hosted a secure HTML website on AWS S3 with a custom Hostinger domain. This setup ensures fast loading speed, global availability, and secure HTTPS hosting.
Need help? Drop a comment below! 🚀