Skip to content

wpwilson10/AWS_Web_Hosting_Infra

Repository files navigation

AWS_Web_Hosting_Infra

This project deploys a serverless single-page application (SPA) using AWS services, with Terraform managing infrastructure as code.

Description

This project provides a low cost but high performance static website hosting solution using AWS services.

This project provisions the following AWS infrastructure using Terraform:

  • Static Website Hosting: Content is stored in an Amazon S3 bucket and served as a static website.
  • Content Delivery Network: Amazon CloudFront caches and accelerates website delivery worldwide.
  • Secure Custom Domain: AWS Certificate Manager (ACM) provides SSL/TLS encryption, and Amazon Route 53 manages DNS (e.g., wpwilson.com).
  • API Gateway for Backend Integration: Amazon API Gateway routes requests to serverless services, including:

Additionally an APIGateway is provisioned which prodvides the REST API routing for other services like the light-schedule-service and logging-service.

This architecture aligns with AWS's Well-Architected Framework for serverless SPA applications by leveraging a serverless, fault-tolerant design.

Architecture

Configuration

Before deploying, create a terraform.tfvars file to define the necessary variables. All variables are defined in variables.tf.

Required Variables

  • domain_name – The domain name for the website (e.g., example.com).
  • github_repo – The GitHub repository managing this project.

Optional Variables (with defaults)

  • api_domain_prefix – Prefix for the API services domain (default: "api").
  • client_file_directory – Path to the directory containing the website's client files (default: "../client/dist/").
  • credentials_profile – AWS credentials profile for authentication (default: "default").
  • project_name – Name used for tagging and organizing resources (default: "SPA-Demo").
  • region – AWS Region to use for deployment (default: "us-east-1").

Setup

1. Initial Deployment

If using a third-party registrar (e.g., GoDaddy, NameCheap), update nameservers to point to the Route 53 hosted zone before proceeding.

2. Deploy with Terraform

Run the following commands from the Terraform directory:

terraform init
terraform plan
terraform apply

Terraform will automatically upload client files to S3 and configure the infrastructure.

Usage

Automatic File Uploads

  • The client files are stored in the local directory specified by the client_file_directory variable (default: ../client/dist/).
  • On terraform apply, Terraform detects changes and automatically uploads modified files to the S3 bucket (client_files_s3_bucket).
  • Files already present and unchanged in S3 will not be re-uploaded, ensuring efficient updates.
  • The CloudFront cache may need to be invalidated if changes are not immediately visible.

Invalidating CloudFront Cache

If updated files do not reflect immediately, manually invalidate the CloudFront cache:

aws cloudfront create-invalidation --distribution-id <DISTRIBUTION_ID> --paths "/*"

About

Deploys a single-page application using AWS services managed with Terraform

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages