->> Day-14 Host A Static Website in AWS S3 And CloudFront (using terraform)
Jenkins
Source: Dev.to | Jan 03, 2026 (UTC)
Introduction:
This mini project demonstrates how to deploy a static website on AWS using Terraform. We’ll create a complete static website hosting solution using S3 for storage and CloudFront for global content delivery.
The Problem with Public S3 Websites?
Hosting a static website directly from S3 by enabling public access has multiple issues:
Security risk: Anyone can access your bucket if misconfigured
Higher latency: Users far from the bucket region experience slower loads
No fine-grained access control
No proper HTTPS management
Production systems require private storage and controlled access, which is where CloudFront comes in.
Architecture
Instead of users accessing S3 directly, we introduce CloudFront as a secure middle layer.
Architecture Flow:
User → CloudFront (HTTPS) → Private S3 Bucket
Enter fullscreen mode
Exit fullscreen mode
What’s happening here?
Users only talk to CloudFront
CloudFront fetches content from S3 securely
S3 remains completely private
Content is cached globally at edge locations
Why Use CloudFront with S3?
Performance
CloudFront caches your static files at edge locations worldwide. A user in India hits a nearby edge location instead of an S3 bucket in us-east-1.
Security
The S3 bucket is not public. Only CloudFront can access it using Origin Access Control (OAC).
Cost Efficiency
Data transfer from S3 → CloudFront is cheaper than S3 → Internet.
Prerequisites
Before starting, make sure you have:
An AWS account
Terraform installed
AWS CLI configured
A basic static website (HTML/CSS/JS)
Step-by-Step Terraform Implementation
Step 1: Create a Private S3 Bucket We start by creating an S3 bucket and explicitly blocking all public access.
Cleanup To destroy all resources and avoid charges:
terraform destroy
Enter fullscreen mode
Exit fullscreen mode
Type yes when prompted to confirm destruction.
Conclusion
Serving static websites directly from public S3 buckets might work for demos, but production systems demand security, performance, and control.
Using CloudFront with a private S3 bucket – provisioned via Terraform – gives you a scalable, secure, and professional setup that mirrors real-world architectures.
Happy building ☁️🚀
Reference
>> Connect With Me
If you enjoyed this post or want to follow my #30DaysOfAWSTerraformChallenge journey, feel free to connect with me here:
Залишити відповідь