Deploying a secure and scalable static website on AWS using Terraform

Published: (December 13, 2025 at 05:27 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Overview

This mini‑project demonstrates the deployment of a secure static website on AWS using Terraform. It provides an end‑to‑end infrastructure‑as‑code solution that leverages Amazon S3 for static content storage and Amazon CloudFront for global content delivery, ensuring high availability, improved performance, and HTTPS‑enabled access through a custom domain.

Architecture

Project architecture

Implementation Steps

Step 1 – Provision S3 bucket

Created an S3 bucket to store static website files and blocked all public access, ensuring the bucket is not directly reachable from the internet.

S3 bucket configuration

Step 2 – Upload website assets

Automatically uploaded all files from the local www/ directory to the S3 bucket and set appropriate MIME content types (HTML, CSS, JS, images).

File upload to S3

Step 3 – Retrieve Route 53 hosted zone

Looked up the existing public Route 53 hosted zone for the domain.

Route 53 hosted zone lookup

Step 4 – Request SSL certificate

Requested an SSL certificate through AWS Certificate Manager (required for CloudFront). The certificate was validated using DNS validation via Route 53.

ACM certificate request

Step 5 – Create CloudFront Origin Access Control (OAC)

Created an OAC so that only CloudFront can read content from the S3 bucket over HTTPS, while direct public access to the bucket remains blocked.

CloudFront OAC configuration

Step 6 – Configure CloudFront distribution

Defined the CloudFront distribution via Terraform resources. The distribution connects users to the content through AWS’s global CDN, reducing latency by caching assets at edge locations.

CloudFront distribution setup

Step 7 – Apply S3 bucket policy

Added a bucket policy that allows s3:GetObject only from the CloudFront distribution using SourceArn conditions.

S3 bucket policy

Step 8 – Create Route 53 alias record

Created a Route 53 alias record that points the custom domain (e.g., www.example.com) to the CloudFront distribution, enabling HTTPS access via the custom domain.

Route 53 alias record

Additional Resources

  • YouTube video:
  • GitHub repository:

Tags: Terraform AWS DevOps

Back to Blog

Related posts

Read more »