This project demonstrates how to host a fully static website on Amazon S3, using Terraform to automate the infrastructure setup and AWS CLI/Jenkins to streamline deployment.
static_website/
βββ aws/ # AWS CLI scripts
β βββ s3_upload.sh
βββ terraform/ # Infrastructure as Code (IaC)
β βββ static-site-s3/ # Module
β β βββ s3.tf
β β βββ variables.tf
β βββ terraform.tf # Root terraform file
β βββ terraform.tfvars # Variables to be defined automatically during runtime
β βββ variables.tf
β βββ outputs.tf
βββ web/ # All website content
βββ css/
β βββ style.css
βββ js/
β βββ script.js
βββ templates/
βββ about.html
βββ contact.html
βββ index.html
- Website:
- Create a basic static website (HTML, CSS, and JavaScript).
- To check that the static website works locally before uploading it to AWS S3, click here.
- AWS S3 Bucket creation with Terraform:
- Create the S3 bucket to host the static website.
- Set appropriate permissions to allow public access to the files.
- Set a globally unique bucket name and region inside .tfvars file.
- AWS S3 Bucket deployment:
- Upload the static website files to the S3 bucket.
- TODO
- Clone this project.
- AWS Configuration:
- Login with IAM user credentials (access/secret key) and configure default region name:
$ aws configureAWS Access Key ID [None]: <accesskey> AWS Secret Access Key [None]: <secretkey> Default region name [None]: <region> Default output format [None]:
- Login with IAM user credentials (access/secret key) and configure default region name:
- AWS S3 Bucket creation with Terraform:
- Go to the Terraform folder:
$ cd static_website/terraform - Initialize and Plan Terraform:
$ terraform init $ terraform plan - Apply Terraform:
$ terraform apply - (optional) To remove the S3 module run:
$ terraform state list | grep module $ terraform state rm module.<module_name>
- Go to the Terraform folder:
- AWS S3 Bucket deployment:
- Run AWS CLI script to upload the web files to the S3 bucket:
$ cd .. $ chmod +x aws/s3_deploy.sh # Give permission to execute $ ./aws/s3_deploy.sh # run script
- TODO
- Run AWS CLI script to upload the web files to the S3 bucket: