This is a fun project I worked on where I learned how to host a simple website using Amazon Web Services (AWS). First, I created a storage space called an S3 bucket to hold my website files. Then, I configured the bucket to allow public access so the site could be viewed online. To make it load faster, I used CloudFront, which helps speed up content delivery. By completing this project, I was able to set up a fully functional website hosted on AWS for free!
I’ll be providing a detailed step-by-step guide below for anyone who wants to follow along and use it as a reference to do the same.
What You’ll Need:
- AWS Account: You’ll need an account with Amazon Web Services (AWS) to access the S3 and CloudFront services.
- Website Files: Have your website files ready to upload, including an
index.html
file and any folders likecss
,img
, orvendor
. - Basic Knowledge of AWS Management Console: Know how to log in and navigate around AWS services like S3 and CloudFront.
- Web Browser: Preferably use Chrome or Firefox to upload files to S3.
- Optional: AWS CLI (Command Line Interface): If there are issues with file uploads, you may use AWS CLI to upload files directly through the command line.
Create an S3 Bucket
- Log in to AWS Console: Go to the AWS Management Console, and in the search bar, type "S3" and select it.
- Create a Bucket: On the S3 dashboard, click the “Create bucket” button.
- Name the Bucket: In the General configuration, type a unique bucket name (e.g.,
my-123456789-bucket
) and select a region. - Allow Public Access: Under "Block Public Access", uncheck the option to block all public access (since we are hosting a static website).
- Create the Bucket: Click “Next” and then “Create bucket”.
- Access Your Bucket: Once created, click on your bucket’s name to open it.
Upload Files to S3 Bucket
- Upload Starter Code: In your bucket, click on the “Upload” button.
- Add Files & Folders: Click “Add files” to upload the
index.html
file, and “Add folder” to upload thecss
,img
, andvendor
folders one by one. Do not upload the folder itself—upload the contents one at a time. - Confirm Upload: Once the files are successfully uploaded, you should see them listed in the bucket.
Secure Your Bucket Using IAM
- Go to Permissions Tab: Open the “Permissions” tab and notice that your bucket allows public access.
- Set Bucket Policy: Click on the “Edit” button under the “Bucket Policy” section, and paste the following policy (replacing
your-website
with your bucket name):
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AddPerm",
"Effect": "Allow",
"Principal": "",
"Action": ["s3:GetObject"],
"Resource": ["arn:aws:s3:::your-website/"]
}
]
}
*This allows your website to be accessed publicly.
Configure S3 for Static Website Hosting
- Go to Properties Tab: In your bucket, open the “Properties” tab and scroll down to the “Static website hosting” section.
- Enable Static Website Hosting: Click “Edit”, enable hosting, and set the index document and error document both to
index.html
. - Save and Copy the Endpoint: After saving, copy the website endpoint for future use. This is the URL where your static website will be hosted.
Distribute Website via CloudFront
- Go to CloudFront Service: In AWS, search for “CloudFront” and select it.
- Create a Distribution: Click “Create Distribution” and then “Get Started” under the delivery method.
- Set Origin Domain: For the origin, paste your bucket’s static website hosting URL (e.g.,
your-bucket-name.s3-website-region.amazonaws.com
). - Use Default Settings: Leave all other options on default and click “Create Distribution”.
- Wait for Deployment: Once the status changes to “Deployed”, copy the CloudFront domain name.
Access Your Website
- Open in Browser: Open a browser and paste the CloudFront domain name (e.g.,
https://dgf7z6g067r6d.cloudfront.net
) to view your website.
Check list:
- S3 Bucket created, visible in the AWS console.
- Website files uploaded to the bucket and public access granted.S3 Bucket created, visible in the AWS console.
- S3 bucket configured for static website hosting.
- Website distributed via CloudFront and accessible to anyone online through a web browser.
- *Remember to terminate all resources after completing the project to avoid accruing charges. This includes terminating the S3 bucket and invalidating the CloudFront distribution. It's also a good practice to regularly monitor your AWS billing dashboard to ensure no unnecessary resources are consuming costs.