Hosting a Zola Static Website on AWS with S3, CloudFront, and ACM

AWS Setup

In this post, we'll walk through the steps needed to host a static website built by Zola on AWS using Amazon S3 for storage, Amazon CloudFront for content delivery, and Amazon Certificate Manager (ACM) for SSL certification. We'll be using this domain name rustronaut.com as an example.

Now that you have decided on using Zola, the one-stop static site engine built using Rust, you will need to host it. Here is one approach I took using AWS services.

Prerequisites
  • Register your domain name, for example rustronaut.com, with Amazon Route 53.
  • Create a bucket that corresponds to your domain. I created one named rustronaut.com.
  • Run the zola build command to generate the static site. All the files will be outputted to the default public directory. Upload these files to your S3 bucket.

Step 1: Configure Your S3 Bucket for Static Website Hosting

Navigate to your rustronaut.com bucket in the S3 service in the AWS Management Console. Under the Properties tab, select Static website hosting. Choose Use this bucket to host a website and enter the name of your index document (typically index.html). Click Save.

Step 2: Make Your Bucket Content Publicly Accessible

Select the Permissions tab in your bucket settings. Click Block all public access, uncheck it, and save the changes.

Navigate to Bucket Policy and enter the following policy:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::rustronaut.com/*"
        }
    ]
}

Step 3: Set Up a CloudFront Distribution

In the AWS Management Console, navigate to the CloudFront service. Click Create Distribution, choose Web, and select Get Started.

For the Origin Domain Name, select your rustronaut.com bucket. For the Viewer Protocol Policy, select Redirect HTTP to HTTPS. Under Cache Key and Origin Request Policy, select Managed-CachingOptimized for the Cache Policy and Managed-AllViewer for the Origin Request Policy.

Enter your domain name, rustronaut.com, under Distribution Settings -> Alternate Domain Names (CNAMEs).

For SSL Certificate, select Request or Import a Certificate with ACM. Here, you'll request a new certificate for rustronaut.com. After a little wait, the certificate should be available for selection. Click Create Distribution.

Step 4: Domain Validation and Certificate Issuance

Once you've requested a new certificate, the status will show as Pending Validation. To validate the domain, follow the instructions in the email that ACM sends to the registered domain owner. Once you validate your domain, the certificate status changes from Pending Validation to Issued, and it becomes available in the ACM console.

Step 5: Point Your Domain to the CloudFront Distribution

Go to the Route 53 service in AWS Management Console and select your domain under Hosted zones. Create a new record set. For Type, choose A - IPv4 address. For Alias, choose Yes. For Alias Target, enter the CloudFront distribution domain name you received in step 3. Click Create.

Step 6: Configure AWS WAF (Optional)

When setting up the CloudFront distribution, you may be asked to select a Web Application Firewall (WAF) policy. Enabling this provides an additional layer of security, but it's optional and may incur additional costs.

After following these steps, you should have a static website hosted on AWS with your custom domain, SSL certificate, and optional WAF security. Propagation can take some time, so don't worry if your site isn't immediately accessible.

Happy hosting!


Software Development

If you're in need of a reliable, experienced, and proficient Rust engineer to strengthen your team and help achieve your project goals, look no further. As a committed team member, I bring my skills to the table, delivering high-quality, efficient, and maintainable code. Let's collaborate and turn your project objectives into robust and efficient solutions. Reach out today to discuss how we can realize your vision together.

Please reach out to discuss rates.

Rust
Rust
PostgreSQL
PostgreSQL
Redis
Redis
MongoDB
MongoDB
Docker
Docker
K8s
K8s
Terraform
Terraform
Linux
Linux
Python
Python
Typescript
Typescript
Node
Node
React
React
Javascript
Javascript
Kafka
Kafka
Java
Java
Jenkins
Jenkins
GCP
GCP
AWS
AWS