Hosting a Static Website on AWS S3: My Experience as a Beginner!

Hosting a Static Website on AWS S3: My Experience as a Beginner!

Recently, I learned how to host a static website on AWS S3, and while it was exciting, I faced several challenges along the way. Let me share my step-by-step process and some lessons I learned so that you can avoid the mistakes I made and easily deploy your own static website.

Steps to Host a Static Website on AWS S3

1. Create an S3 Bucket

  • First, go to your AWS S3 dashboard and click on Create bucket.

  • Name your bucket (for example, my-first-website) if you're using a custom domain, the bucket name must match the domain name.

  • Make sure to uncheck the option Block all public access if you want your website to be publicly accessible.
    Lesson learned: I initially forgot to uncheck this and couldn’t access my website. It took me some time to figure it out!

2. Upload Your Static Files

  • Upload your website files like index.html, images, CSS, and JavaScript.

  • You can simply drag and drop the files into the bucket or use the Upload button on the dashboard.

    Tip: Organize your files well so it’s easy to manage, especially if your site has multiple folders.

3. Configure Static Website Hosting

  • In your S3 bucket, go to the Properties tab.

  • Scroll down to Static website hosting and enable it.

  • Set the Index Document (like index.html) and Error Document (like 404.html).

  • Save the changes.

    Lesson learned: Forgetting to set the index.html here caused my site to show an error instead of loading the homepage.

4. Update the Bucket Policy

  • Go to the Permissions tab and find the Bucket Policy section.

  • Click on Edit and add the following JSON code to allow public access:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::your-bucket-name/*"
    }
  ]
}
  • Replace your-bucket-name with the actual name of your bucket.
    Lesson learned: I had a small typo (a missing comma), which caused my policy to fail. Double-check your JSON before saving!

5. Access Your Website

  • Once everything is set up, go back to the Static website hosting section in the Properties tab.

  • Copy the S3 website URL and paste it into your browser. Your site should load now!

6. (Optional) Custom Domain Setup

  • If you have a domain (like from GoDaddy or Namecheap), you can link it to your S3 bucket.

  • Add a CNAME record in your domain settings pointing to your S3 bucket URL.

  • Make sure your bucket name matches your domain name for this to work properly.
    Lesson learned: This part was confusing at first, but AWS documentation helped a lot.

Challenges I Faced as a Beginner

  1. Bucket Policy Issues:
    A single missing comma in the JSON caused errors, and I had to redo the policy multiple times.

  2. Public Access Settings:
    Forgetting to uncheck "Block all public access" delayed my deployment.

  3. Custom Domain Confusion:
    I didn’t realize the bucket name must match the domain name exactly. This caused my custom domain to fail initially.

Final Thoughts

Hosting a static website on AWS S3 was a great learning experience. Even though I faced some challenges, I realized how powerful and simple S3 is for hosting websites. If you're a beginner, don’t worry about making mistakes—that’s how you learn!

Take your time, follow these steps, and soon you’ll be hosting your own website like a pro. 🚀

If you have questions or need help, feel free to reach out. Let’s learn and grow together! 😊