Host static frontend applications on AWS using CloudFront and S3.
This module creates a complete infrastructure for hosting static sites including ACM certificates, CloudFront distribution with Origin Access Control (OAC), and optionally an S3 bucket.
|
Important
|
CloudFront distributions can take 15-30 minutes to deploy or update. |
module "static_site" {
source = "github.com/nsbno/terraform-aws-multi-domain-static-site?ref=x.y.z"
service_name = "petstore"
domain_name = {
name = "petstore.test.infrademo.vydev.io"
zone = data.aws_route53_zone.main.name
}
}See the full basic example here.
module "static_site" {
source = "github.com/nsbno/terraform-aws-multi-domain-static-site?ref=x.y.z"
service_name = "petstore"
domain_name = {
name = "petstore.test.infrademo.vydev.io"
zone = data.aws_route53_zone.main.name
}
use_external_bucket = true
website_bucket = aws_s3_bucket.existing.id
}These examples show you how to use this module in different configurations.
A simple single-domain static site setup.
Using multiple domains with subject alternative names (SANs).
Bring your own S3 bucket instead of creating a new one.
Configure cache TTL settings and CloudFront price class.
V1 of this module uses Origin Access Identity (OAI) for CloudFront to access the S3 bucket.
V2 uses the newer Origin Access Control (OAC) which provides better security and performance.
To upgrade from V1 to V2, follow these steps:
-
Add this variable to the module:
keep_oai_for_migration = trueand run Terraform apply once to create the OAC while keeping the OAI for migration.
-
Remove or set variable to false:
keep_oai_for_migration = false