A Step-by-Step Guide to hosting your website on AWS S3
Published: 2023-08-07 12:36:40

**Introduction**
A static website is a type of website that uses HTML, CSS, and JavaScript to display content without the need for server-side scripting or databases. This makes them ideal for displaying simple webpages with fixed content, such as brochure sites, portfolios, and product catalogs. Static websites are often faster to load and easier to maintain since they don’t require regular updates or additional coding. Therefore, many businesses and organizations choose to host their websites this way to save on costs while still providing an attractive and functional website.

Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance. Customers of all sizes and industries can use Amazon S3 to store and protect any amount of data for a range of use cases, such as data lakes, websites, mobile applications, backup and restore, archive, enterprise applications, IoT devices, and big data analytics. Amazon S3 provides management features so that you can optimize, organize, and configure access to your data to meet your specific business, organizational, and compliance requirements.
 In this step-by-step guide, we’ll show you how to host your website on AWS S3

**Step 1 Creating a bucket**

•	Sign in to the AWS Management Console and open the Amazon S3 console at  https://console.aws.amazon.com/s3/
•	Choose Create bucket. The Create bucket page opens.
•	For Bucket name, enter a name for your bucket. (The bucket name must be unique because S3 is a global service) 
•	For Region, choose the AWS Region where you want the bucket to reside.
•	You can leave other settings has they are or adjust based on your needs 
•	Click on create bucket button to create your bucket 

![Amzons3page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/papi6k570grwgz6xzohz.PNG)


![Creating a bucket](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/whot99sy45q42s1od2jx.PNG)


![Bucket created succesfully](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fins7jz75eh0vbic0yre.PNG)

**Step 2 Upload your website files** 
 
•	Navigate to the bucket created in step 1 above and click on it 
•	Choose Upload.
•	In the Upload window, do one of the following:
o	Drag and drop the website files (index.html) to the Upload window.
o	Choose Add file, choose the files to upload, and choose Open.
•	To upload the website file, navigate to the bottom of the page, choose Upload.
•	Amazon S3 uploads your objects and folders. When the upload is finished, you see a success message on the Upload: status page.


![Object Upload](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/va9aaee5zo6f5ldb0r7a.PNG)


![Uploading website file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ec8ypf5cp1tlrawgs4if.png)


![File uploaded](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uigygct5fwqehcc0o4va.png)





**Step 3 Enabling website hosting**
 
•	Navigate to the bucket created in step 1 above and click on it
•	Choose Properties and scroll down
•	Under Static website hosting, choose Edit.
•	Choose Use this bucket to host a website.
•	Under Static website hosting, choose Enable.
•	In Index document, enter the file name of the index document, typically index.html.
•	To provide your own custom error document for 4XX class errors, in Error document, enter the custom error document file name.
•	Choose Save changes.
o	Amazon S3 enables static website hosting for your bucket. At the bottom of the page, under Static website hosting, you see the website endpoint for your bucket.


![static website](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hs46vsxg635quhluqoym.png)


![editing static website hosting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ytli3148x9ybq7zau1f0.png)


![website hosting enabled](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h771ggb44cx8j33w7esa.png)






**Step 4 Setting permissions for website access**

**A. Unblocking public access to your bucket**
•	Navigate to the bucket created in step 1 above and click on it
•	Choose Permissions.
•	Under Block public access (bucket settings), choose Edit.
•	Clear Block all public access, and choose Save changes. (This will enable public access to the bucket)


![Permission overview for public access](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ztewylh9rr9bf5e7lc84.png)


![|Editing public access ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wg085sohsndmwpznwtzk.png)


**B. Adding a Bucket Policy** - To make the objects in your bucket publicly readable, you must write a bucket policy that grants everyone s3:GetObject permission.

•	Navigate to the bucket created in step1 above and click on it.
•	Choose Permissions.
•	Under Bucket Policy, choose Edit.
•	To grant public read access for your website, copy the following bucket policy, and paste it in the Bucket policy editor.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::Bucket-Name/*"
            ]
        }
    ]
}


•	Update the Resource to your bucket name.
o	To use this bucket policy with your own bucket, you must update this name to match your bucket name.
•	Choose Save changes


![Adding bucket policy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8to8sfcupcger55jko5p.png)


![public access bucket policy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xw4imld8agvj40p3scfz.png)


At this point you can verify your website access by copying the website endpoint URL provided in the “Static website hosting” section and pasting it on your web browser


![Website endpoint url](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xzf7b8s7fq6mhyu76gyi.png)

Your website is displayed below 


![website displayed](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sqvsnpo4ni2o8b7fp8d3.png)

 


 Bucket Policy are used to grant public read permission to the objects owned by the bucket owner. However, if your bucket contains objects that aren't owned by the bucket owner, the bucket owner should use the object access control list (ACL) to grant public READ permission on those objects.

**C. Access Control List (ACL) **
•	Navigate to the bucket created in step1 above and click on it.
•	Choose Permissions and scroll down to object ownership
•	Under Object Ownership, choose Edit.
•	Check the box for ACLs enabled and check the box to acknowledge ACL will be restored and save changes. Then edit the ACl 
•	Ensure that the “Read” box “Everyone (public access)” is checked.
•	Make sure that the object (index.html file) in the bucket is made public as well 


![my bucket](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m0k8yeykougzq5gfaa6o.png)


![Edit ownership](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c5v8a9h2axusw4pgwsr0.png)


![Enable Acl](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2n4vlf3lbgw7m0xcly32.png)


![Edit Acl](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tae51kio2zubjuaefz87.png)




![Allow Read access on ACl for everyone](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tm6pgvmh5nw7zpf3uwlr.png)


![Making Object public Using Acl](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ajn017idzeszz8y9tsxv.png)


![Object made public](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k9n1jf9oui5r11jjrdyf.png)



**Step 5 Verifying Your Website Access**
•	Copy the website endpoint URL provided in the “Static website hosting” section 
•	Paste the website endpoint URL into the address bar of your browser and hit Enter.
•	If everything went smoothly, your website should load up, displaying the content from the index.html file. That means your S3 bucket is hosting your static website and can be accessed by anyone on the internet.


![Website endpoint url](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xzm9ezc3is9h9i2e7bxh.png)


![website displayed](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s5g9rs7xrbzvozl6v6uh.png)

Congratulations! you have successfully hosted a static website on Amazon s3. 
In the next publication i will be using Terraform (IaC) to deploy a static website on Amazon S3.

Thanks for reading.