Hosting Static Website Using AWS CloudFront and S3

Introduction to Amazon CloudFront and S3 Integration

In the world of cloud computing, optimizing the delivery of web content is crucial for providing a seamless user experience. Amazon CloudFront, a content delivery network (CDN) service offered by AWS, plays a pivotal role in accelerating the distribution of static and dynamic web content. When integrated with Amazon S3, CloudFront ensures that your content is delivered quickly and reliably to users around the globe.

CloudFront works by caching copies of your web content at edge locations worldwide, which are strategically placed data centers. This minimizes latency and improves the speed at which your content is delivered to end users. By distributing content across multiple edge locations, CloudFront significantly reduces the load on your origin servers, leading to better scalability and performance.

How CloudFront Works with S3

When you host your static website or other content on Amazon S3, you can use CloudFront to enhance the delivery of that content. Here’s how the integration works:

This integration between CloudFront and S3 not only improves the speed and reliability of content delivery but also reduces costs by minimizing the amount of data transferred from S3, thanks to CloudFront’s caching capabilities. Whether you’re delivering a simple static website or rich media content, using CloudFront with S3 is a powerful way to ensure fast, scalable, and secure content delivery across the globe.

cloudfront-architecture

How to Set Up AWS CloudFront and S3 for Static Website Hosting

Are you looking to host a static website without breaking the bank? AWS offers a powerful and cost-effective solution through S3 (Simple Storage Service) and CloudFront, all within its free tier. In this blog post, we'll walk you through the steps to set up a static website using these AWS services, and the best part is that you can do it all for free.

Step 1: Create an S3 Bucket

The first step in hosting your website is to create an S3 bucket where your website files will be stored.

Step 2: Upload Your Website Files to the S3 Bucket

With your bucket ready, it’s time to upload your website files and configure the S3 Bucket for Static Website Hosting.

Step 3: Creating a CloudFront Distribution in the AWS Free Tier

Amazon CloudFront is a content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to your viewers with low latency and high transfer speeds. In this guide, we'll walk you through the steps to create a CloudFront distribution using the AWS free tier. We'll configure the distribution to work without a custom domain (alternate domain), and accept GET and PUT requests, ensuring that you can deliver content efficiently and securely.

Steps to Create CloudFront Distribution

  1. Navigate to the AWS CloudFront Console.
  2. Create a new distribution by clicking Create Distribution.
  3. Select your Origin (S3 bucket or HTTP server).
  4. Configure the origin with the appropriate settings.
  5. Set Allowed HTTP Methods to include GET and PUT.
  6. Leave the Alternate Domain Names (CNAMEs) empty.
  7. Use the default CloudFront SSL certificate.
  8. Review your settings and create the distribution.
  9. Wait for deployment and test using the provided CloudFront URL.

Step 5: Check Your Live Website Using CloudFront Distribution Domain Name

1. Get the CloudFront Distribution Domain Name

Follow these steps to retrieve your CloudFront distribution domain name:

2. Access the Website

Once you have the CloudFront domain name, you can access your website as follows:

Distribution-domain-name

3. Verify Content Delivery

Ensure that your website content is loading as expected. If everything appears correctly, your CloudFront distribution is functioning properly.

5. Troubleshoot if Needed

If the website does not load, consider the following troubleshooting steps:

6. Configuring a Custom Error Page in CloudFront (if Access diclined)

If your website is not running, you can configure a custom error page in CloudFront. Follow these steps to set up your custom error page, such as an `index.html` file.

Steps to Configure Custom Error Page

  1. Navigate to CloudFront Console:
  2. Edit Distribution Settings:
    • Click on the Distribution Settings button.
page1
  1. Go to Error Pages Tab:
    • In the distribution settings, navigate to the Error Pages tab.
page2
  1. Create Custom Error Response:
    • Click the Create Custom Error Response button.
  2. Configure Error Response:
    • Set the HTTP Error Code (e.g., 403, 404, 500) that you want to handle. (if Access diclined or 403 forbidden shown -- choose 403 forbidden)
page3 page4
  • Save and Deploy:
  • Contact Us