This is a simple Terraform module that deploys a static website to an S3 bucket and creates a CloudFront distribution in front of it. The module also creates a Route 53 record set for the website.
- Hosted zone in Route 53
- ACM certificate for the domain
After the deployment, you will need to upload the website content to the S3 bucket and create a CloudFront invalidation to update the cache.
You can use the output deployment_commands
to get the commands to do this.
module "deployment" {
source = "github.com/2012160085/terraform-aws-s3-cloudfront-deployment"
domain = "www.my-domain.com"
hosted_zone_name = "my-domain.com"
s3_bucket_name = "my-bucket"
acm_certificate_arn = "arn:aws:acm:us-east-1:123456789012:certificate/12341234-asdf-1234-1234-asdfasdfasdf"
}
output "deployment_commands" {
value = module.deployment.deployment_commands
}
hosted_zone_name
- The name of the hosted zone in Route 53domain
- The domain name of the websiteacm_certificate_arn
- The ARN of the ACM certificate
s3_bucket_name
- The name of the S3 bucketdefault_root_object
- The default root object of the website (default
:index.html
)
deployment_commands
- The commands to upload the website content and create a CloudFront invalidation.#example aws s3 sync path/to/website s3://my-bucket --exclude ".git/*" aws cloudfront create-invalidation --distribution-id E1234567890 --paths "/*"