Learn how to host a static website on Amazon S3 and CloudFront. Set up S3 website hosting, create a CloudFront distribution, and publish easily.
Hosting a static website can be simple and affordable. If your website contains only HTML, CSS, JavaScript, and image files, Amazon S3 and CloudFront provide a reliable way to publish it online. This guide explains the setup process step by step and shows how these AWS services work together to host a static website. If you need expert assistance with AWS infrastructure, Bobcares AWS Managed Services help simplify deployment, management, and maintenance of cloud environments.
Overview
What Is a Static Website?
A static website contains content that does not change dynamically. It usually includes:
- HTML files
- CSS for styling
- JavaScript for basic interactivity
- Images or other media
Common examples include personal portfolios, blogs, landing pages, and documentation sites.
Why Use Amazon S3 and CloudFront?
Amazon S3 stores your website files and serves them as a website. CloudFront is a Content Delivery Network (CDN) that delivers content from locations closer to users, helping pages load faster.
Additionally, this combination is cost-effective, scalable, and highly available.
Need Help Managing Your Hybrid Cloud Environment?
Step 1: Create an S3 Bucket
Create an S3 bucket by following these steps:
- Open the Amazon S3 service in the AWS Management Console.
- Create a new bucket.
- Enter a unique bucket name, usually matching your website name.
- Select a region.
- Disable Block all public access because the website must be publicly accessible.
- Create the bucket.
Step 2: Upload Website Files
Upload your website files, including index.html, CSS, JavaScript, images, and other static content, to the bucket.
Ensure the main page is named index.html, since Amazon S3 uses it as the default page.
Step 3: Enable Static Website Hosting
Enable static website hosting in the bucket:
- Open the S3 bucket.
- Select the Properties tab.
- Enable Static website hosting.
- Set the Index document to index.html.
- Save the changes.
Amazon S3 then provides a website endpoint URL.
Step 4: Make the Bucket Public
Add a bucket policy that allows public read access.
As a result, users can access your website files through a web browser. Once this step is complete, the website is available using the S3 website endpoint.
Step 5: Create a CloudFront Distribution
Set up a CloudFront distribution by completing these steps:
- Open CloudFront in the AWS Management Console.
- Create a new distribution.
- Select the S3 website endpoint as the origin.
- Keep the remaining settings at their default values.
- Create the distribution.
CloudFront generates a new URL for your website.
Step 6: Access Your Website
After a few minutes, the CloudFront distribution becomes available.
Open the CloudFront URL in your browser. Your static website is now live, loads faster, and is accessible globally.
Benefits of This Setup
Using Amazon S3 and CloudFront provides several advantages:
- Faster loading through CloudFront
- Low cost for small websites
- No servers to manage
- Automatic scalability
- High availability
Conclusion
Hosting a static website with Amazon S3 and CloudFront is a simple and dependable way to publish your website. This setup provides fast access, scalability, and high availability without requiring server management. Finally, if you need assistance deploying or managing AWS hosting environments, Bobcares can help with AWS infrastructure and cloud support services.