This repository now uses a reusable Terraform module for deploying a static website to AWS CloudFront. You can deploy separate environments (development and production) using the same module.
modules/static-site/
: The reusable module containing all resources.development/
: Environment-specific configuration for development.production/
: Environment-specific configuration for production.
- Terraform >= 1.10
- AWS credentials with permissions for S3, CloudFront, ACM, and Route53
- A registered domain in Route53
- Configure variables
- Edit
development/variables.tf
andproduction/variables.tf
as needed. - Provide values for
s3_bucket_name
,domain_name
, andsubject_alternative_name
in a.tfvars
file (e.g.,development.tfvars
).
- Edit
- Initialize Terraform
cd development # or production terraform init
- Plan and apply
terraform plan terraform apply
- Upload your static site files
aws s3 cp ./public/ s3://<your-bucket-name>/ --recursive
Repeat the above steps in the production
directory for production deployment.
S3 rewrites URLs so /about
and /about/
both serve /about/index.html
.
There is a cost associated with this CloudFront functions: $0.10 per 1 million invocations.
MIT