Skip to main content

S3 Static Site

πŸ“¦ Overview​

This Terraform module provisions an Amazon S3 bucket configured for static website hosting, designed to serve public-facing HTML, CSS, and JavaScript assets.

It’s ideal for simple web apps, landing pages, and frontend prototypes that need globally accessible, lightweight hosting.


βœ… Key Features​

  • Enables public read access for static content delivery
  • Configures root and error documents for S3 website hosting
  • Uses a globally unique bucket name with a random suffix
  • Adds environment-based tags for tracking and organization

πŸ’Ό Use Cases​

  • Hosting landing pages, prototypes, or product microsites
  • Deploying simple client-side SPAs or documentation portals
  • Serving assets without needing EC2 or server infrastructure
  • Fast deployments for hackathons, demos, or MVPs

πŸ“₯ Input Variables​

NameTypeDescription
regionstringAWS region to deploy the S3 static site bucket
bucket_base_namestringBase name for the S3 bucket (random suffix will be appended)
environmentstringTag to specify the deployment environment (e.g., dev, staging, prod)
index_documentstringName of the root document for the website (e.g., index.html)
error_documentstringName of the error document to serve (e.g., 404.html)

πŸ“€ Outputs​

NameDescription
bucket_nameThe full name of the S3 static site bucket
website_endpointThe public URL of the hosted static website

πŸš€ Deployment Readiness​

  • βœ… Compatible with Terraform 1.0+
  • βœ… Tested with AWS provider 5.x
  • πŸ§ͺ Requires IAM permissions for S3 and public access configuration

πŸ› οΈ Example Usage​

module "s3_static_site" {
source = "git::ssh://git@github.com/archiphire/aws-level-1-modules.git//storage/s3-static-site?ref=v1.0.0"

region = "us-east-1"
bucket_base_name = "archiphire-landing"
environment = "dev"
index_document = "index.html"
error_document = "404.html"
}
terraform init
terraform plan
terraform apply

or

tofu init
tofu plan
tofu apply

Upload your static site files:

aws s3 sync ./site s3://"bucket_name" --acl public-read

🧹 Cleanup Options​

Terraform Destroy (for test environments):

terraform destroy

or

tofu destroy

⚠️ This will remove the S3 bucket and all its contents. Be sure to back up any hosted files before destruction.

πŸ›‘οΈ Notes​

This is a Level 1 module intended for lightweight public hosting. For more secure or production-grade hosting, pair this with:

cloudfront-static-site s3-secure-bucket

πŸ”’ Deployment Package Notice​

This module is part of the Level 1 AWS License Tier. To access the full deployment package and source code, subscribe to Archiphire.