
Host a Secure Static Website with Amazon S3 and CloudFront
Learn how to deploy a fast and scalable static website using Amazon S3 and Amazon CloudFront, with HTTPS and controlled access to your website content.
Host a Secure Static Website with Amazon S3 and CloudFront
Static websites are an excellent use case for cloud storage and content delivery networks.
Instead of running a web server, we can store HTML, CSS, JavaScript, images, and other static files in Amazon S3 and deliver them through Amazon CloudFront.
AWS recommends CloudFront for secure static website architectures because it can provide HTTPS and use Origin Access Control to restrict direct access to an S3 origin. {"fallbackMarkdown":"( AWS Documentation )","reference":{"matched_text":"","prefix":null,"start_idx":7871,"end_idx":7903,"safe_urls":[" https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html","https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm\_source=chatgpt.com","https://docs.aws.amazon.com/en\_en/AmazonS3/latest/userguide/HostingWebsiteOnS3Setup.html","https://docs.aws.amazon.com/en\_en/AmazonS3/latest/userguide/HostingWebsiteOnS3Setup.html?utm\_source=chatgpt.com"],"refs":\[],"alt":"([AWS Documentation]( https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm_source=chatgpt.com))","prompt\_text"\:null,"type":"grouped\_webpages","fallback\_items"\:null,"items":\[\{"title":"Get started with a secure static website - Amazon CloudFront","url":" https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm\_source=chatgpt.com","attribution":"AWS Documentation","pub_date":null,"snippet":"","attribution_segments":null,"supporting_websites":[{"title":"Tutorial: Configuring a static website on Amazon S3 - Amazon Simple Storage Service","url":" https://docs.aws.amazon.com/en\_en/AmazonS3/latest/userguide/HostingWebsiteOnS3Setup.html?utm\_source=chatgpt.com","pub\_date"\:null,"snippet":"","attribution":"AWS Documentation"}],"refs":[{"turn_index":0,"ref_type":"search","ref_index":1},{"turn_index":0,"ref_type":"search","ref_index":2}],"hue":null,"attributions":null}],"error":null,"status":"done","style":null},"showLoginRequiredCard":false}
Architecture
The architecture looks like this:
┌───────────────┐ │ User │ └───────┬───────┘ │ ▼ ┌───────────────┐ │ CloudFront │ │ CDN │ └───────┬───────┘ │ ▼ ┌───────────────┐ │ S3 │ │ Website Files │ └───────────────┘
Route 53 → CloudFront ACM → HTTPS Certificate
CloudFront caches website content at edge locations so that subsequent requests can be served closer to users. {"fallbackMarkdown":"( AWS Documentation )","reference":{"matched_text":"","prefix":null,"start_idx":8692,"end_idx":8711,"safe_urls":[" https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html","https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm\_source=chatgpt.com"],"refs":\[],"alt":"([AWS Documentation]( https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm_source=chatgpt.com))","prompt\_text"\:null,"type":"grouped\_webpages","fallback\_items"\:null,"items":\[\{"title":"Get started with a secure static website - Amazon CloudFront","url":" https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm\_source=chatgpt.com","attribution":"AWS Documentation","pub_date":null,"snippet":"","attribution_segments":null,"supporting_websites":[],"refs":[{"turn_index":0,"ref_type":"search","ref_index":1}],"hue":null,"attributions":null}],"error":null,"status":"done","style":null},"showLoginRequiredCard":false}
Step 1: Create the Website
Create a simple
index.html file:<!DOCTYPE html><html><head> <title>My AWS Website</title></head><body>
<h1>Welcome to My AWS Website</h1>
<p> This website is hosted using Amazon S3 and delivered through Amazon CloudFront. </p>
</body></html>
You can also add:
style.cssscript.jsimages/
to create a complete static website.
Step 2: Create an S3 Bucket
Create an Amazon S3 bucket for your website files.
For a secure CloudFront-based architecture, the S3 bucket can remain private while CloudFront accesses it through Origin Access Control. AWS documents this approach as a way to prevent users from directly accessing the S3 origin. {"fallbackMarkdown":"( AWS Documentation )","reference":{"matched_text":"","prefix":null,"start_idx":9455,"end_idx":9474,"safe_urls":[" https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html","https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm\_source=chatgpt.com"],"refs":\[],"alt":"([AWS Documentation]( https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm_source=chatgpt.com))","prompt\_text"\:null,"type":"grouped\_webpages","fallback\_items"\:null,"items":\[\{"title":"Get started with a secure static website - Amazon CloudFront","url":" https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm\_source=chatgpt.com","attribution":"AWS Documentation","pub_date":null,"snippet":"","attribution_segments":null,"supporting_websites":[],"refs":[{"turn_index":0,"ref_type":"search","ref_index":1}],"hue":null,"attributions":null}],"error":null,"status":"done","style":null},"showLoginRequiredCard":false}
Upload:
index.htmlstyle.cssscript.jsimages/
to the bucket.
Step 3: Create a CloudFront Distribution
Create a CloudFront distribution and select your S3 bucket as the origin.
Configure Origin Access Control so that requests to the S3 content are served through CloudFront.
The request flow becomes:
Browser | vCloudFront | vS3
If the requested object is already cached, CloudFront can return it directly from the cache. Otherwise, CloudFront retrieves the object from S3 and caches it for future requests. {"fallbackMarkdown":"( AWS Documentation )","reference":{"matched_text":"","prefix":null,"start_idx":10033,"end_idx":10052,"safe_urls":[" https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html","https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm\_source=chatgpt.com"],"refs":\[],"alt":"([AWS Documentation]( https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm_source=chatgpt.com))","prompt\_text"\:null,"type":"grouped\_webpages","fallback\_items"\:null,"items":\[\{"title":"Get started with a secure static website - Amazon CloudFront","url":" https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm\_source=chatgpt.com","attribution":"AWS Documentation","pub_date":null,"snippet":"","attribution_segments":null,"supporting_websites":[],"refs":[{"turn_index":0,"ref_type":"search","ref_index":1}],"hue":null,"attributions":null}],"error":null,"status":"done","style":null},"showLoginRequiredCard":false}
Step 4: Enable HTTPS
HTTPS protects communication between users and your website.
AWS Certificate Manager can provide the TLS certificate used by CloudFront in this architecture. AWS's secure static website solution combines CloudFront with ACM for HTTPS. {"fallbackMarkdown":"( AWS Documentation )","reference":{"matched_text":"","prefix":null,"start_idx":10315,"end_idx":10334,"safe_urls":[" https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html","https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm\_source=chatgpt.com"],"refs":\[],"alt":"([AWS Documentation]( https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm_source=chatgpt.com))","prompt\_text"\:null,"type":"grouped\_webpages","fallback\_items"\:null,"items":\[\{"title":"Get started with a secure static website - Amazon CloudFront","url":" https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm\_source=chatgpt.com","attribution":"AWS Documentation","pub_date":null,"snippet":"","attribution_segments":null,"supporting_websites":[],"refs":[{"turn_index":0,"ref_type":"search","ref_index":1}],"hue":null,"attributions":null}],"error":null,"status":"done","style":null},"showLoginRequiredCard":false}
Configure your CloudFront distribution with the certificate.
Your website can then be accessed using:
https://example.com
instead of plain HTTP.
Step 5: Add a Custom Domain
If you own a domain such as:
example.com
you can use Amazon Route 53 to manage DNS.
The architecture becomes:
User | vRoute 53 | vCloudFront | vS3
Route 53 directs users to CloudFront, while CloudFront retrieves the website content from S3.
Step 6: Test the Website
Open your CloudFront domain in a browser.
You should see:
Welcome to My AWS Website
This website is hosted using Amazon S3and delivered through Amazon CloudFront.
Now update
index.html , upload the new version to S3, and invalidate the CloudFront cache when necessary.Why Use CloudFront?
CloudFront provides several advantages for static websites.
Global delivery
Content can be cached at CloudFront edge locations closer to users.
HTTPS
CloudFront can serve the website securely over HTTPS.
Caching
Frequently requested files can be served from the CloudFront cache.
Reduced origin requests
Cached objects reduce the number of requests that need to reach the S3 origin.
Security
Origin Access Control can restrict direct access to the S3 origin. {"fallbackMarkdown":"( AWS Documentation )","reference":{"matched_text":"","prefix":null,"start_idx":11645,"end_idx":11664,"safe_urls":[" https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html","https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm\_source=chatgpt.com"],"refs":\[],"alt":"([AWS Documentation]( https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm_source=chatgpt.com))","prompt\_text"\:null,"type":"grouped\_webpages","fallback\_items"\:null,"items":\[\{"title":"Get started with a secure static website - Amazon CloudFront","url":" https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/getting-started-secure-static-website-cloudformation-template.html?utm\_source=chatgpt.com","attribution":"AWS Documentation","pub_date":null,"snippet":"","attribution_segments":null,"supporting_websites":[],"refs":[{"turn_index":0,"ref_type":"search","ref_index":1}],"hue":null,"attributions":null}],"error":null,"status":"done","style":null},"showLoginRequiredCard":false}
Security Best Practices
Avoid making your S3 bucket unnecessarily public.
AWS notes that direct S3 static website hosting requires public access and only supports HTTP. For a secure website, CloudFront can provide HTTPS and controlled access to an S3 origin. {"fallbackMarkdown":"( AWS Documentation )","reference":{"matched_text":"","prefix":null,"start_idx":11930,"end_idx":11949,"safe_urls":[" https://docs.aws.amazon.com/en\_en/AmazonS3/latest/userguide/HostingWebsiteOnS3Setup.html","https://docs.aws.amazon.com/en\_en/AmazonS3/latest/userguide/HostingWebsiteOnS3Setup.html?utm\_source=chatgpt.com"],"refs":\[],"alt":"([AWS Documentation]( https://docs.aws.amazon.com/en_en/AmazonS3/latest/userguide/HostingWebsiteOnS3Setup.html?utm_source=chatgpt.com))","prompt\_text"\:null,"type":"grouped\_webpages","fallback\_items"\:null,"items":\[\{"title":"Tutorial : Configuring a static website on Amazon S3 - Amazon Simple Storage Service","url":" https://docs.aws.amazon.com/en\_en/AmazonS3/latest/userguide/HostingWebsiteOnS3Setup.html?utm\_source=chatgpt.com","attribution":"AWS Documentation","pub_date":null,"snippet":"","attribution_segments":null,"supporting_websites":[],"refs":[{"turn_index":0,"ref_type":"search","ref_index":2}],"hue":null,"attributions":null}],"error":null,"status":"done","style":null},"showLoginRequiredCard":false}
Recommended practices include:
- Keep sensitive files out of the website bucket.
- Use CloudFront Origin Access Control.
- Use HTTPS.
- Use least-privilege IAM permissions.
- Enable logging where appropriate.
- Configure appropriate cache policies.
- Protect administrative AWS accounts with strong authentication.
Deployment Automation
Once the website works, deployment can be automated.
A CI/CD workflow could look like:
Developer | vGit Repository | vBuild Pipeline | vS3 | vCloudFront | vUsers
Every time the website changes, the pipeline can automatically upload the new files and update the distribution.
Cost Considerations
One advantage of a static website is that you don't need to maintain a continuously running web server.
S3 provides storage while CloudFront delivers the content.
Actual AWS costs depend on storage, requests, data transfer, CloudFront usage, and other configuration choices, so review current AWS pricing before deploying a production workload.
Conclusion
Amazon S3 and CloudFront provide a powerful architecture for hosting static websites.
The basic design is simple:
Route 53 ↓CloudFront ↓S3
With HTTPS, Origin Access Control, caching, and DNS, this architecture can provide a secure and scalable foundation for portfolios, documentation sites, landing pages, and frontend applications.
For production deployments, you can extend the architecture with CI/CD, monitoring, custom domains, security controls, and infrastructure as code.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article