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β
| Name | Type | Description |
|---|---|---|
| region | string | AWS region to deploy the S3 static site bucket |
| bucket_base_name | string | Base name for the S3 bucket (random suffix will be appended) |
| environment | string | Tag to specify the deployment environment (e.g., dev, staging, prod) |
| index_document | string | Name of the root document for the website (e.g., index.html) |
| error_document | string | Name of the error document to serve (e.g., 404.html) |
π€ Outputsβ
| Name | Description |
|---|---|
| bucket_name | The full name of the S3 static site bucket |
| website_endpoint | The 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.