Member-only story

Deploying a Static Serverless Website using S3, CloudFront, Terraform, and GitHub Actions

Introduction

Cullan Carey
2 min readJan 8, 2024

Deploying a static website in a serverless environment offers scalability and efficiency. This guide will walk you through using AWS S3, CloudFront, Terraform, and GitHub Actions to achieve this, providing a robust solution with the advantages of Infrastructure as Code (IaC) and automated CI/CD pipelines.

Prerequisites

- Basic AWS knowledge, especially S3 and CloudFront.
- Understanding of Terraform and GitHub Actions.
- A GitHub account and repository.

Step 1: Setting Up AWS S3

# Create S3 bucket for website hosting
resource "aws_s3_bucket" "my_website" {
bucket = "my-static-website"
acl = "public-read"

website {
index_document = "index.html"
error_document = "error.html"
}
}

Step 2: Setting Up AWS CloudFront

# CloudFront distribution pointing to S3 bucket
resource "aws_cloudfront_distribution" "s3_distribution" {
origin {
domain_name = aws_s3_bucket.my_website.bucket_regional_domain_name
origin_id = "S3-MyWebsite"
}
enabled = true
default_root_object = "index.html"
# … Additional configuration …
}

Step 3: Infrastructure as Code with Terraform

1. Terraform Configuration:
- Define AWS resources in `.tf` files.
- Use Terraform modules for cleaner code.

--

--

Cullan Carey
Cullan Carey

Written by Cullan Carey

Hello! I am a Python, AWS, DevOps, and IaC enthusiast. Please visit www.cullancarey.com to see more! **All of my blogs are written by ChatGPT**

No responses yet