โ Part One: Prerequisites Preparation
Preparation Checklist
- AWS Account (with payment method activated)
- Your own domain name (e.g.: example.com)
- Website files ready (HTML/CSS/JS)
- Browser open to AWS Console (console.aws.amazon.com)
Key Concepts Understanding
- S3 Bucket: Container for storing website files
- CloudFront: Global CDN, accelerates content distribution
- Route53: DNS resolution service, associates domains
- ACM: Free SSL/TLS certificate service
- OAC: Origin Access Control, ensures only CloudFront can access S3
๐พPart Two: S3 Bucket Creation and Configuration
1Create an S3 Bucket
Path: AWS Console Home โ S3 โ Buckets โ Create Bucket
Detailed Steps
- Sign in to AWS Console
- In the top search box, type
S3โ Click to enter S3 service - In the left sidebar, click "Buckets"
- Click the "Create bucket" button (blue)
Fill Out the Form
2Enable Static Website Hosting
Path: S3 Bucket โ Properties โ Edit Static Website Hosting
Detailed Steps
- Click on the bucket name you just created (example-com-website)
- Click the "Properties" tab (fifth from the right)
- Scroll down to find the "Static Website Hosting" section
- Click the "Edit" button
Configuration Items
- Page displays "โ Update Completed"
- Under "Static Website Hosting" displays "Enabled"
- You will see a website endpoint URL
3Upload Website Files
Path: S3 Bucket โ Objects โ Upload
File Structure Example
Upload Methods
Drag the website folder into the upload area, supports recursive uploading of subfolders
Method B: Click to Select
Click "Add file" or "Add folder" and select files one by one
- See upload progress reach 100%
- After returning to bucket, see list of all files
๐Part Three: Create Origin Access Control (OAC)
4Create OAC
Path: CloudFront โ Security โ Origin Access
Detailed Steps
- In the top search box, type
CloudFrontโ Enter CloudFront service - In the left sidebar, expand the "Security" menu
- Click "Origin Access"
- Click the "Create Origin Access Control" button
Fill Out the Form
- Newly created OAC appears on page
- Copy the OAC ID shown (e.g.: E127EXAMPLE51Z)
โกPart Four: Create CloudFront Distribution
5Create CloudFront Distribution
Path: CloudFront โ Distributions โ Create Distribution
Origin Configuration - Origin Section
Default Cache Behavior Configuration
Distribution Configuration
6Copy CloudFront Domain Name
Path: CloudFront โ Distributions โ Distribution Details
- After distribution is created, click on the Distribution ID
- In the "Distribution Details" tab view the following information
- Copy the distribution domain name (d111111abcd.cloudfront.net)
7Apply S3 Bucket Policy
Path: S3 โ Bucket โ Permissions โ Bucket Policy
Operation Steps
- Return to S3 service
- Select your website bucket (example-com-website)
- Click the "Permissions" tab
- Scroll down to find "Bucket Policy" and click "Edit"
- Paste the following JSON into the edit box
Bucket Policy JSON (requires modification)
example-com-websiteโ Replace with your bucket name123456789012โ Replace with your AWS Account IDE1234ABCDโ Replace with your CloudFront Distribution ID
๐Part Five: ACM Certificate Request
8Request SSL/TLS Certificate
Path: ACM (AWS Certificate Manager) โ Certificates โ Request Certificate
Important Note
Detailed Steps
- In the top search box, type
Certificate Managerโ Enter ACM service - Make sure the region is US East (N. Virginia)
- Click the "Request Certificate" button
Fill Out the Form
Subsequent DNS Validation
After requesting, the page will prompt you to validate the domain:
- In the "Domain Validation" section you will see validation records
- Click the "Create Route53 Record" button
- AWS will automatically add a CNAME record in Route53
- Wait 5-30 minutes, status will change to "Issued"
๐Part Six: Route53 DNS Configuration
9Create Route53 Hosted Zone
Path: Route53 โ Hosted Zones โ Create Hosted Zone
Detailed Steps
- In the top search box, type
Route53โ Enter Route53 service - In the left sidebar, click "Hosted Zones"
- Click the "Create Hosted Zone" button
Fill Out the Form
Record Important Information
10Update Domain Registrar DNS Settings
Operate at Domain Registrar (such as GoDaddy, Namecheap, Aliyun, etc.)
Steps
- Log in to your domain registrar account
- Find "DNS Management" or "Domain Management"
- Modify Name Servers (NS Records) to the 4 you copied above
- Save changes
11Create Alias Records in Route53
Path: Route53 โ Hosted Zones โ Create Record
Create First Record (Root Domain)
Create Second Record (www Subdomain)
Repeat the steps above, but change "Record Name" to www, rest of configuration is the same.
12Configure CloudFront CNAME and Certificate
Path: CloudFront โ Distributions โ Edit
Steps
- Return to CloudFront service
- Select your distribution (click on Distribution ID)
- Click the "Edit" button
- Find the "Alternate Domain Names (CNAME)" field
- Click the input box and add two domain names
Select SSL Certificate
โ๏ธPart Seven: Configure Caching Policy
13Set Cache for Different File Types
Path: CloudFront โ Distributions โ Behaviors โ Edit
This step is used to optimize costs and performance. Set different cache times for different file types.
Default Behavior Configuration
Optional: Create Separate Behavior for HTML
For finer control, you can create different behavior rules for different file types:
โ๏ธPart Eight: Testing and Verification
14Test Website Access
Test URLs
Success Indicators
- โ Page loads normally
- โ HTTPS is valid (address bar shows lock icon)
- โ Certificate information is correct (click lock icon to view)
Troubleshooting Table
| Problem | Cause | Solution |
|---|---|---|
| Shows AWS S3 error page | S3 bucket policy not configured correctly | Check distribution ID in bucket policy |
| Shows "Access Denied" | OAC not applied correctly | Confirm OAC exists in S3 bucket policy |
| Custom domain name not working | Route53 DNS not in effect | Wait for DNS propagation (maximum 48 hours) |
| Invalid SSL certificate | ACM certificate not deployed to CloudFront | Select correct certificate in CloudFront |
| Access is slow | Cache not working | Check Cache-Control header configuration |
๐Part Nine: Performance Optimization
15Configure Cache Header Optimization
Setting appropriate Cache-Control headers for files in S3 can significantly reduce costs and improve performance.
Method A: Through AWS Console
- S3 โ Bucket โ Objects
- Select file โ "Object Actions" โ "Edit Metadata"
- Add custom metadata (Key: Cache-Control)
Cache Time Recommendations
| File Type | Cache-Control Value | Description |
|---|---|---|
| HTML File | public, max-age=300, must-revalidate |
5 minutes, must revalidate |
| CSS/JS/Image | public, max-age=31536000, immutable |
1 year, requires versioned filenames |
| API Response | public, max-age=0 |
No cache, get latest each time |
Method B: Through AWS CLI
16Enable Gzip Compression
Enabling automatic compression in CloudFront can reduce traffic by 60-70%.
Steps
- CloudFront โ Distributions โ Edit
- Find "Default Cache Behavior"
- Check "Enable Compression" โ
๐Part Ten: Monitoring and Cost Control
17Set Up Monitoring Alerts
Monitor CloudFront Costs
- Enter CloudWatch or Cost Management
- Set up budget alerts
Monitor Key Performance Indicators
View the following metrics in CloudFront distribution:
- Number of Requests: Total requests per day
- Data Transfer Volume: Size of outbound traffic
- Cache Hit Rate: Should be > 90%
- Error Rate: Should be close to 0%
Cost Estimation Table (Monthly)
| Service | Cost | Description |
|---|---|---|
| S3 Storage | $0.23 | 10GB ร $0.023 |
| S3 GET Requests | $0.04 | 1M รท 1000 ร $0.0004 |
| CloudFront Outbound | Free | 1TB free tier (100GB used) |
| CloudFront Requests | Free | 10M free tier (1M used) |
| Route53 | $0.50 | Hosted zone monthly fee |
| ACM Certificate | Free | Free for AWS internal use |
| Total | $0.77/month |
Frequently Asked Questions
Q1: How do I update website files?
Q2: How do I clear CloudFront cache?
- CloudFront โ Distributions โ Invalidations
- Create Invalidation โ Enter path
/*โ Create
Q3: What is the data transfer flow of S3 + CloudFront?
Q4: How do I implement HTTPS redirect?
Already configured in CloudFront:
- Viewer Protocol Policy: Redirect HTTP to HTTPS
All HTTP requests will be automatically redirected to HTTPS.
โ Summary Checklist
After Deployment, Verify the Following Items
- S3 bucket created and files uploaded
- Static website hosting enabled (index.html, error.html)
- OAC created
- CloudFront distribution created and deployed
- ACM certificate requested and verified
- Route53 hosted zone created
- Domain registrar DNS updated to Route53 NS
- Alias records (A records) created
- CloudFront CNAME configured
- CloudFront ACM certificate applied
- https://example.com accessible normally
- Cache policy optimized
- Compression enabled
- Cost monitoring set up
Subsequent Maintenance
Daily Operations
- Regularly check CloudFront cache hit rate (should be > 90%)
- Monitor monthly costs
- Use
aws s3 synccommand when updating website content
Regular Maintenance
- Check ACM certificate expiration date (auto-renewal)
- Verify Route53 DNS configuration is correct
- Clean up old S3 object versions (if versioning is enabled)
Performance Optimization
- Use CloudFront real-time logs to analyze cache hit rate
- Regularly adjust Cache-Control header configuration
- Consider using Lambda@Edge for edge computing
๐ Deployment Complete
You now have a production-grade, low-cost static website hosting solution
๐ Cost: $0.50 - $5 average per month
โก Performance: Global < 500ms load time
๐ Security: HTTPS + DDoS protection
๐ Scalability: Automatically handles traffic growth