AWS Builder Center
Static website on Amazon S3: what the beginner lab teaches and what changes in production

Static website on Amazon S3: what the beginner lab teaches and what changes in production

I'm a final-year Computer Science student in Quito, Ecuador, preparing for the AWS Certified Cloud Practitioner exam. This week I finished the AWS Educate course Getting Started with Storage, which ends with a hands-on simulation: hosting a static website on Amazon S3. These are my notes, plus what I learned about doing the same thing the way AWS recommends today.

Computer Science student · Aspiring Cloud & AI Engineer.

What the lab does, in eight steps

  1. Create the bucket. The name must be globally unique (3–63 characters: lowercase letters, numbers, dots and hyphens). The lab enables ACLs, turns off Block all public access, enables versioning and adds a tag.
  1. Enable static website hosting in Properties, with  index.html  and  error.html .
  1. Open the website endpoint and get a 403 Forbidden.
  1. Upload  index.html ,  script.js  and  style.css . Still 403.
  1. Make the objects public using ACLs. Now the site loads.
  1. Share a private file with a presigned URL that expires after 2 minutes. After that, Access denied.
  1. Add a bucket policy that denies  s3:DeleteObject  on the site files, then try to delete  index.html . It fails.
  1. Update the site by uploading a new  index.html  and check Show versions: two versions of the same key.

Four things that clicked for me

1. A 403 is good news here. It means hosting is working but the objects are private. In S3, everything is private by default.
2. Presigned URLs are the answer to "share this file, but only for a while". Anyone who has the link can use it until it expires, so keep the expiry short.
3. An explicit  Deny  wins. This is the policy from step 7:
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "DenyDeleteSiteFiles",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:DeleteObject",
"Resource": [
"arn:aws:s3:::my-bucket/index.html",
"arn:aws:s3:::my-bucket/script.js",
"arn:aws:s3:::my-bucket/style.css"
]
}]
}
Even I, the bucket owner, couldn't delete the files. An explicit deny overrides any allow.
4. You don't edit objects, you replace them. S3 is object storage, so a change means uploading the whole file again. With versioning on, the old version is kept and can be restored. Versioning can't be turned off once enabled, only suspended.

What I would change for a real site

The lab is a great introduction, but two of its choices aren't what AWS recommends for new buckets:
  • ACLs. New buckets have ACLs disabled by default (Bucket owner enforced), and AWS recommends keeping them that way and controlling access with policies.
  • A public bucket. The common production pattern keeps Block Public Access on and puts Amazon CloudFront in front, with Origin Access Control (OAC) so that only CloudFront can read the bucket.
What that gets you:
  • HTTPS. The S3 website endpoint only serves HTTP.
  • Caching at edge locations, closer to users.
  • A private bucket. Nobody can bypass CloudFront and read objects directly.
One detail to watch: with OAC, CloudFront uses the bucket's REST endpoint, not the website endpoint, so you set a default root object ( index.html ) in the distribution.

The same basics from the AWS CLI

aws s3 mb s3://my-bucket
aws s3 sync ./site s3://my-bucket
aws s3 presign s3://my-bucket/report.png --expires-in 120

What's next

I'm building a web platform for my thesis, a multi-agent traffic simulation for congestion pricing in Quito. I plan to deploy its frontend with S3 + CloudFront + OAC, and I'll write about that here.
If you've deployed a static site this way: do you handle cache invalidation on every deploy, or use versioned file names?
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article