This project automates the deployment of a static website on AWS using Terraform. The infrastructure includes an S3 bucket to store website files, a CloudFront distribution for global content delivery, and appropriate configurations to ensure the website is publicly accessible and secure.
This project demonstrates how to deploy a static website on AWS using:
- S3: For storing website files.
- CloudFront: For distributing content with a CDN.
- Terraform: To automate the provisioning of resources.
To run this project, you will need:
- An AWS account with the necessary permissions to create S3 buckets, CloudFront distributions, and other resources.
- Terraform installed on your local machine. You can download it from here.
- AWS crednetials shared with Terraform. This will allow you to run your terraform code in your AWS account.
- See this guide you can also view this article for more information.
- Basic knowledge of AWS and Terraform.
.
├── cloudfront.tf # Terraform configuration file for Cloudfront distribution
├── s3.tf # Terraform configuration file for s3 bucket
├── main.tf # Terraform configuration file for other resources
├── README.md # Project documentation (this file)
└── src # Folder containing website files
├── index.html # Your main website HTML file
└── error.html # Your error page HTML file
First clone the repository to your local machine
open s3.tf
and change bucket
to a globally unique name
check main.tf
and ensure the AWS region
in the provider block is correct for your needs
run terraform init
to initalise the terraform environment
run terraform plan
to ensure your AWS account is configured and review the plan ensuring you are happy with what will be deployed
run terraform apply
to create the S3 bucket, upload your website files, and set up cloudfront
Once the deployment is complete, Terraform will output the CloudFront URL. Visit the URL in your browser to see your static website live
To prevent incuring any unnesseccary AWS costs, you can destroy the infrastructure when it is no longer needed using terraform destroy
Note: this command will remove all resources that were created by terraform