This project demonstrates how to host a static website using Amazon Simple Storage Service (S3) and deliver the content globally with Amazon CloudFront, a Content Delivery Network (CDN).
Amazon S3 provides secure, scalable, and reliable storage for your website files. CloudFront improves website performance by caching your content in multiple edge locations worldwide, reducing latency for users.
- Configure static website hosting on Amazon S3
- Configure Amazon CloudFront distributions to work with S3 static websites
- Secure your website by restricting S3 bucket access to CloudFront only
- Go to AWS Console.
- Log in using your AWS credentials.
- In the AWS Console search bar, type S3, and select S3 under Services.
- Click Create bucket in the top-right corner.
- Under General configuration, fill in:
- Bucket name:
demo-bucket-
+ unique number (bucket names must be globally unique) - Region: Select your preferred region, e.g., US West (Oregon) us-west-2
- Bucket name:
- Enable ACLs (Access Control Lists).
- Under Block Public Access, uncheck Block all public access.
- Confirm by checking I acknowledge that the current settings might result in this bucket and the objects within becoming public.
- Scroll down and click Create bucket.
- Click your newly created bucket name in the S3 console.
- Go to the Properties tab.
- Scroll down to Static website hosting and click Edit.
- Select Enable.
- Set:
- Index document:
index.html
- Error document:
error.html
- Index document:
- Click Save changes.
- In the S3 console, open your bucket and click the Permissions tab.
- Scroll down to Bucket policy and click Edit.
- Paste the following policy, replacing
YOUR_BUCKET_NAME
with your bucket name:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"
}
]
}
- Go to the Objects tab in your bucket.
- Click Upload → Add files.
- Select all your website files and folders (make sure
index.html
is at the root level). - Click Upload.
- Go to the Properties tab.
- Scroll down to Bucket website endpoint and click the copy icon.
- Paste the URL in your browser — you should see your website load.
Amazon CloudFront speeds up your website by caching content in edge locations worldwide.
- In AWS Console, search for CloudFront and open it.
- Click Create Distribution → Get Started under Web.
- Under Origin domain, enter your S3 static website endpoint URL (from Step 3).
- Under Origin access control, select Create control setting:
- Name: demo-s3cf- + unique number
- Signing behavior: Sign requests
- Click Create.
- Leave other settings as default.
- Under Price Class, select Use only North America and Europe (optional to reduce cost).
- In Default root object, enter
index.html
. - Click Create distribution.
- After distribution creation, click Copy policy from the CloudFront distribution page.
- Return to your S3 bucket’s Permissions tab → Bucket policy → Edit.
- Replace your current bucket policy with the copied policy to allow access only from CloudFront.
- Click Save changes.
- In your S3 bucket, under Permissions → Block public access, click Edit.
- Check Block all public access and save.
- Confirm by typing
confirm
.
This restricts public access directly to the S3 bucket, forcing users to go through CloudFront.
- Go to the CloudFront Distributions list.
- Wait until the distribution status is Enabled (can take 10-15 minutes).
- Copy the Distribution Domain Name (e.g.,
abc123.cloudfront.net
). - Paste the URL in a browser — your website should load via CloudFront.
- Created an Amazon S3 bucket configured for static website hosting.
- Uploaded website files and made them publicly accessible.
- Created a CloudFront distribution to cache and deliver website content globally.