CloudFront +s3 Tutorial: How I Hosted my Portfolio Securely on AWS
Source: Dev.to
Prerequisites
- AWS account (Free Tier works)
- Static website build (React/Vite or plain HTML/CSS/JS)
- Basic familiarity with AWS Console
Step 1: Build & Upload Portfolio Files to S3
Before uploading, create an optimized production build.
For React/Vite:
npm run build
This creates a dist/build folder containing:
index.htmlviteassets/(folder)
Upload only these files (not your source code) to S3:
- Create a bucket.
- Keep Block Public Access ON.
- Open the S3 console.
- Upload the
dist/buildfiles into the bucket root.
Step 2: Enable Static Website Hosting (Optional)
- Go to the bucket Properties.
- Scroll to Static Website Hosting and enable it.
- Set the Index document to
index.html.
Step 3: Create CloudFront Distribution
- Open the CloudFront console.
- Click Create Distribution.
- Select your S3 bucket as the origin.
- For Origin Access, choose Origin Access Control (OAC).
- CloudFront will generate the necessary permissions and apply them to your bucket.
This keeps the S3 bucket private while CloudFront handles public routing.
Step 4: Restrict Direct S3 Access
CloudFront provides a bucket policy that you paste into the bucket permissions. This ensures:
- The bucket is not publicly readable.
- Only CloudFront can serve the content.
Step 5: Set Default Root Object
In the CloudFront distribution settings, set Default Root Object to index.html. This allows the portfolio to load without explicitly typing the file name.
Step 6: Wait for Deployment & Test
Deployment may take a few minutes. Once complete, you’ll receive a domain such as:
d37dnhohvgt3x2.cloudfront.net
Visit the domain to see the portfolio live and secure.
Using S3 + CloudFront provides a private bucket, follows production best practices, remains free‑tier friendly, and benefits from global performance improvements.
Tags: aws cloud cloudfront s3 webdev portfolio tutorial
If you found this helpful, please leave a ❤️ or bookmark it!