Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 11, 2022 06:08 am GMT

Creating a static website with Amazon S3

This project is a static website that shows the top 10 cat pictures ever using Amazon S3.

Stage 1: Creating an S3 bucket

Image description

Image description
Remember, every S3 bucket must have a unique name. My choice of using a domain URL as a bucket name is because I already registered a domain animals4life295.link with Route53 earlier in the course, since I would love to direct my bucket to my registered domain later in the project, my bucket name needs to correlate with my registered Route53 domain. I also unchecked block all public access so it can be used as a static website since it must be available to everybody. Unchecking this means we will be able to grant public access, although not automatically.
Stage 2: Enabling static website hosting and uploading files

Image description
Right now, I can only access the S3 API and control UI, but I need to be able to host our static website. So, I must enable static website hosting on my S3 bucket. I went to the properties tab of my bucket, scrolled to the bottom, and enabled static website hosting. I also set my index and error document.

After that, I uploaded my files and folders to my S3 bucket

Image description
Stage 3: Enabling static website hosting and uploading files

Image description
I tried accessing my static website after uploading my files, but I got an error page. Remember, I checked off block all public access in stage 1? Now, I need to define a bucket policy that makes the static website public.

Image description
I went to the permissions tab of my bucket and edited my pocket policy, which allows public read access to my S3 bucket. It worked!!

Image description
Stage 4: Directing my S3 bucket to my registered domain
Up till this point, I have been accessing my static website with my bucket website endpoint. I dont want that; I want to access my static website with a normal URL.

Image description
So, I moved to my Route53 console, went to Hosted Zones, and selected my animals4life295.link zone and then proceeded to add a record. The reason for doing that is to point my registered domain to my S3 bucket.

Image description
After setting and saving this record I was able to access my S3 bucket directly from a domain top10.animals4life295.link which is also the name of my bucket!

Image description


Original Link: https://dev.to/mohtasham/creating-a-static-website-with-amazon-s3-3e0g

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To