Skip to content

ashyT-Cloud/cloudfront-secure-static-website

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Secure Static Website Hosting on AWS using Terraform, Amazon S3 & CloudFront

A production-inspired DevOps project demonstrating secure static website hosting using Terraform, Amazon S3, Amazon CloudFront, Origin Access Control (OAC), and GitHub Actions CI/CD.

AWS Terraform GitHub Actions License


๐Ÿ“Œ Project Overview

This project demonstrates how to securely host a static website on AWS following modern cloud security and DevOps best practices.

Instead of making the Amazon S3 bucket public, the website is served through Amazon CloudFront using Origin Access Control (OAC). Infrastructure is provisioned using Terraform, while GitHub Actions automates validation and deployment.

This repository was built as a portfolio project to demonstrate Infrastructure as Code (IaC), CI/CD automation, AWS cloud services, and secure architecture design.


๐Ÿ—๏ธ Architecture

Architecture

Architecture Flow

User
   โ”‚
 HTTPS
   โ”‚
   โ–ผ
Amazon CloudFront
   โ”‚
Origin Access Control (OAC)
   โ”‚
   โ–ผ
Private Amazon S3 Bucket

Terraform provisions and manages the infrastructure while using:

  • Amazon S3 for Remote Terraform State
  • Amazon DynamoDB for State Locking

โœจ Features

  • Secure Static Website Hosting
  • Private Amazon S3 Bucket
  • Amazon CloudFront Distribution
  • Origin Access Control (OAC)
  • HTTPS Content Delivery
  • Infrastructure as Code with Terraform
  • Remote Terraform State
  • DynamoDB State Locking
  • GitHub Actions CI Pipeline
  • Automated Website Deployment
  • CloudFront Cache Invalidation
  • Version Controlled Infrastructure
  • Production-inspired Repository Structure

โ˜๏ธ AWS Services Used

  • Amazon S3
  • Amazon CloudFront
  • Origin Access Control (OAC)
  • AWS IAM
  • Amazon DynamoDB

๐Ÿ› ๏ธ Technologies Used

  • Terraform
  • AWS CLI
  • Git
  • GitHub
  • GitHub Actions
  • HTML5
  • CSS3
  • JavaScript

๐Ÿ“ Repository Structure

.
โ”œโ”€โ”€ .github/
โ”‚   โ””โ”€โ”€ workflows/
โ”‚       โ””โ”€โ”€ deploy.yml
โ”‚
โ”œโ”€โ”€ bootstrap/
โ”‚   โ””โ”€โ”€ backend/
โ”‚
โ”œโ”€โ”€ terraform/
โ”‚   โ”œโ”€โ”€ backend.tf
โ”‚   โ”œโ”€โ”€ bucket-policy.tf
โ”‚   โ”œโ”€โ”€ cloudfront.tf
โ”‚   โ”œโ”€โ”€ outputs.tf
โ”‚   โ”œโ”€โ”€ providers.tf
โ”‚   โ”œโ”€โ”€ s3.tf
โ”‚   โ”œโ”€โ”€ variables.tf
โ”‚   โ””โ”€โ”€ versions.tf
โ”‚
โ”œโ”€โ”€ website/
โ”‚   โ”œโ”€โ”€ assets/
โ”‚   โ”œโ”€โ”€ css/
โ”‚   โ”œโ”€โ”€ js/
โ”‚   โ””โ”€โ”€ index.html
โ”‚
โ”œโ”€โ”€ docs/
โ”‚   โ”œโ”€โ”€ architecture/
โ”‚   โ”œโ”€โ”€ screenshots/
โ”‚   โ””โ”€โ”€ decisions.md
โ”‚
โ””โ”€โ”€ README.md

๐Ÿ” Security Best Practices

โœ” Amazon S3 Block Public Access enabled

โœ” Private S3 Bucket

โœ” CloudFront Origin Access Control (OAC)

โœ” Infrastructure managed using Terraform

โœ” Terraform Remote Backend

โœ” DynamoDB State Locking

โœ” IAM User for GitHub Actions Deployment

โœ” GitHub Repository Secrets for AWS Credentials


โš™๏ธ Infrastructure Provisioned

Terraform provisions the following AWS resources:

  • S3 Bucket (Website)
  • S3 Bucket Versioning
  • Public Access Block
  • Bucket Policy
  • CloudFront Distribution
  • Origin Access Control
  • Remote State Bucket
  • DynamoDB Lock Table

๐Ÿš€ CI/CD Pipeline

The deployment pipeline is powered by GitHub Actions.

Workflow

Developer
     โ”‚
git push
     โ”‚
     โ–ผ
GitHub Actions
     โ”‚
     โ”œโ”€โ”€ Checkout Repository
     โ”œโ”€โ”€ Terraform Format Check
     โ”œโ”€โ”€ Terraform Validate
     โ”œโ”€โ”€ Validate Website Files
     โ”œโ”€โ”€ Upload Website to Amazon S3
     โ””โ”€โ”€ CloudFront Cache Invalidation

๐Ÿ“ท Screenshots

Home Page

Home


Amazon CloudFront

CloudFront

CloudFront securely delivers website content over HTTPS using Origin access Control (OAC).


GitHub Actions

GitHub Actions

The CI/CD pipeline validates Terraform, uploads the website to Amazon S3, and invalidates the Cloudfront cache automatically after every push to the main branch.

Terraform Apply

Terraform


๐Ÿ“Š Project Highlights

  • Infrastructure as Code with Terraform
  • Secure Static Website Hosting on AWS
  • Private Amazon S3 Bucket
  • Amazon CloudFront with Origin Access Control (OAC)
  • Remote Terraform Backend (S3 + DynamoDB)
  • Automated CI/CD with GitHub Actions

๐Ÿงฉ Key Challenges & Solutions

Challenge Solution
AWS account verification blocked CloudFront creation Waited for AWS account verification and resumed deployment
CloudFront returned Access Denied Uploaded website content to the private S3 bucket and verified Origin Access Control (OAC)
Workflow file placed in the wrong directory Moved the workflow to .github/workflows
Git commits made on the wrong branch Reviewed the branch history and completed the release work on main
Terraform backend warning Kept the current implementation and documented the newer use_lockfile approach for future enhancement

๐Ÿ“š Learning Outcomes

This project strengthened my practical understanding of AWS cloud services, Infrastructure as Code, secure static website hosting, CI/CD automation, Git workflows, and production-inspired DevOps practices.


๐Ÿ”ฎ Future Improvements

  • Route 53 Integration
  • Custom Domain
  • AWS Certificate Manager (ACM)
  • GitHub OIDC Authentication
  • AWS WAF
  • CloudFront Logging
  • S3 Access Logging
  • CloudWatch Monitoring
  • Terraform Modules
  • Multi-Environment Deployment (Dev/Stage/Prod)

๐ŸŒ Deployment Status

The infrastructure for this project has been successfully deployed and validated on AWS using Terraform.

To minimize AWS costs, the infrastructure may be destroyed when not actively being demonstrated. The repository includes architecture diagrams, deployment screenshots, and Infrastructure as Code to fully document the implementation.

๐Ÿ’ก What I Learned

Building this project gave me hands-on experience with:

  • Designing secure AWS architectures using Amazon S3 and CloudFront
  • Implementing Infrastructure as Code using Terraform
  • Managing remote Terraform state with Amazon S3 and DynamoDB
  • Building CI/CD pipelines using GitHub Actions
  • Troubleshooting real-world deployment issues
  • Applying Git branching strategies and version control best practices

๐Ÿ‘จโ€๐Ÿ’ป Author

Ashish Thakur

Aspiring DevOps & Cloud Engineer

Skills: AWS โ€ข Terraform โ€ข Docker โ€ข Kubernetes โ€ข Git โ€ข GitHub Actions โ€ข Linux

GitHub: https://github.com/ashyT-Cloud


โญ If you found this project helpful, consider giving it a Star!

About

Secure static website hosting on AWS using Terraform, Amazon S3, CloudFront (OAC), and GitHub Actions CI/CD.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors