Terraform module for creating an s3 static website with Cloudfront distribution
The following resources will be created
- S3 Bucket
- CloudFront distribution
- Route53 record
- Upload sample HTML file (optional)
Prerequisites (Optional in example2):
- Route 53 hosted zone for example.com
- ACM certificate for
*.example.com in us-east-1 region
provider "aws" {
region = "us-east-1"
}
module "cloudfront_s3_website_with_domain" {
source = "chgangaraju/cloudfront-s3-website/aws"
version = "1.2.6"
hosted_zone = "example.com"
domain_name = "test.abc.example.com"
acm_certificate_domain = "*.abc.example.com"
upload_sample_file = true
}
module "cloudfront_s3_website_without_domain" {
source = "chgangaraju/cloudfront-s3-website/aws"
version = "1.2.6"
domain_name = "test-application-1232" // Any random identifier for s3 bucket name
use_default_domain = true
upload_sample_file = true
}
- CloudFront caches the static content at default values. However, if you change it constantly without recreating the bucket, you may need to decrease the TTL values.
# optional values
cloudfront_min_ttl = 10
cloudfront_default_ttl = 1400
cloudfront_max_ttl = 86400