You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Amazon S3 is not just a place to store files — it can also serve an entire static website directly from a bucket. Combined with CloudFront and Transfer Acceleration, S3 delivers content globally with low latency and high transfer speeds.
S3 can host static websites consisting of HTML, CSS, JavaScript, images, and other client-side files. There is no server-side processing — every file is served exactly as stored.
| Good For | Not Suitable For |
|---|---|
| Single-page applications (React, Vue, Angular) | Server-side rendering (Node.js, PHP, Python) |
| Marketing and landing pages | Database-backed applications |
| Documentation sites | User authentication flows |
| Portfolio or blog sites (pre-built) | Dynamic API endpoints |
Step 1: Create a bucket with the website name
aws s3 mb s3://my-static-site-example
Step 2: Enable static website hosting
aws s3 website s3://my-static-site-example \
--index-document index.html \
--error-document error.html
Step 3: Disable Block Public Access (required for public websites)
aws s3api put-public-access-block \
--bucket my-static-site-example \
--public-access-block-configuration \
BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false
Step 4: Add a bucket policy to allow public reads
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-static-site-example/*"
}
]
}
aws s3api put-bucket-policy --bucket my-static-site-example --policy file://website-policy.json
Step 5: Upload your website files
aws s3 sync ./build/ s3://my-static-site-example/
The website endpoint follows this pattern:
http://<bucket-name>.s3-website-<region>.amazonaws.com
For example: http://my-static-site-example.s3-website-eu-west-2.amazonaws.com
Note: The website endpoint uses HTTP, not HTTPS. For HTTPS, you need CloudFront.
Amazon CloudFront is a content delivery network (CDN) that caches your website at edge locations around the world.
| Benefit | Description |
|---|---|
| HTTPS | Free SSL/TLS certificate via AWS Certificate Manager |
| Custom domain | Use your own domain name (e.g. www.example.com) |
| Caching | Content cached at 400+ edge locations globally |
| Lower latency | Users are served from the nearest edge location |
| DDoS protection | Built-in AWS Shield Standard |
User → CloudFront (Edge Location) → S3 Bucket (Origin)
CloudFront retrieves the content from S3 on the first request, caches it, and serves subsequent requests directly from the edge — much faster than fetching from S3 every time.
Instead of making the bucket public, you can keep it private and let CloudFront access it using Origin Access Control:
This is the recommended approach — your bucket stays private while CloudFront serves the content publicly.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.