pedroMMM / aws-static-site-fancy

"Fancy" Static Site Hosting on AWS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Fancy" Static Site Hosting Terraform Module on AWS

Problem Statement

Write a Terraform module for generating the infrastructure needed for hosting a static website/app on AWS.

The code should include resources for:

  • Storing the static site content
  • Serving the content with a CDN
  • Providing hosted zone and cname for the site

The solution should support:

  • Creating multiple separate environments - E.g. make it easy to deploy to new environments without manual work in AWS UI
  • Reuse without changing/removing hard-coded strings within the resource blocks
  • Providing inputs/outputs so that the code could be invoked from a CI or other system

Extra credit for...

  • Cloudwatch resources to help monitor the site
  • WAF for providing additional security capabilities
  • Log delivery to S3/Athena for downstream analysis
  • Integration (even partial) with any of the AWS Code* CI/CD tools

Local Development

AWS resources for Terraform Module local development are under the local directory.

  1. Copy pedro.tfvars file naming it after the user.
  2. Modify the new file to create a new subdomain on a domain you control.
  3. Run Terraform via:
    1. Prepare Terraform using terraform init
    2. Plan the Terraform changes and review using terraform plan -var-file <yourname>.tfvars -out tfplan
    3. Apply Terraform changes via terraform apply tfplan
  4. Add a NS records on the domain your control for the new Route53 Hosted Zone. The NS record should have the same name as your Hosted Zone. Use the Terraform output for the answers, depending on the DNS host it can a single or multiple answers.

Deployment

The Terraform module is been used by 2 environments, dev and prd. We can only upload new static site content by creating a new version and host it on the dev environment. Once happy with the current dev version it must then be promoted to prd.

  1. Create a new static site version with ./do.sh version-up <version>.
  2. Test and accept the version in the dev environment.
  3. Promote the static site artifact from dev to prd with ./do.sh promote.

About

"Fancy" Static Site Hosting on AWS

License:MIT License


Languages

Language:HCL 88.9%Language:Shell 9.5%Language:HTML 1.5%